在IOS中通过HTTP流式传输视频 [英] Streaming video over HTTP in IOS

查看:267
本文介绍了在IOS中通过HTTP流式传输视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我的应用程序。该应用程序需要通过服务器在iPhone上播放视频。我有一个视频链接 http://www.cwtmedia.se/cwtvideo.mp4 。任何机构都可以建议我如何在MPMoviePlayerController上执行此操作。我正在使用此代码,但它不起作用。

I am am working on my app.which have requirement play video on iPhone by server. I have a video link http://www.cwtmedia.se/cwtvideo.mp4 . Can any body suggest me how i perform this on MPMoviePlayerController.I am using this code for that but its not working.

enter code here


NSURL *url = [NSURL fileURLWithPath:@"http://www.cwtmedia.se/cwtvideo.mp4"];
moviePlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer1.view];
moviePlayer1.view.frame = CGRectMake(0, 0, 320, 416); 
moviePlayer1.fullscreen=YES;
[moviePlayer1 setFullscreen:NO animated:YES];
moviePlayer1.controlStyle = MPMovieControlStyleFullscreen;

[moviePlayer1 play];


推荐答案

顺便说一句,这是我如何使用mpmovieplayercontroller进行流式传输:

by the way here's how i use mpmovieplayercontroller for streaming :

NSURL *url = [NSURL URLWithString:videoUrl];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleDefault];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
CGRect frame;
if(self.interfaceOrientation ==UIInterfaceOrientationPortrait)
    frame = CGRectMake(20, 69, 280, 170);
else if(self.interfaceOrientation ==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation ==UIInterfaceOrientationLandscapeRight)
    frame = CGRectMake(20, 61, 210, 170);
[moviePlayer.view setFrame:frame];  // player's frame must match parent's
[self.view addSubview: moviePlayer.view];
[self.view bringSubviewToFront:moviePlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayer];

[moviePlayer prepareToPlay];
[moviePlayer play];

然后是委托方法:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
       MPMoviePlayerController *player = [notification object];
       [[NSNotificationCenter defaultCenter] 
            removeObserver:self
            name:MPMoviePlayerPlaybackDidFinishNotification
            object:player];

       if ([player respondsToSelector:@selector(setFullscreen:animated:)]){
          //self.navigationController.navigationBarHidden = YES;
          [player.view removeFromSuperview];
       }
}

希望这会对你有帮助..

hope this will help you..

这篇关于在IOS中通过HTTP流式传输视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆