[英]Streaming video over HTTP in IOS
I am am working on my app.which have requirement play video on iPhone by server. 我正在开发我的app.app有要求在iPhone上通过服务器播放视频。 I have a video link http://www.cwtmedia.se/cwtvideo.mp4 .
我有一个视频链接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.
任何人都可以建议我如何在MPMoviePlayerController上执行此操作。我正在为此使用此代码,但无法正常工作。
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];
by the way here's how i use mpmovieplayercontroller for streaming : 顺便说一下,这是我使用mpmovieplayercontroller进行流式传输的方式:
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];
and then here's the delegate method : 然后是委托方法:
- (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.. 希望能帮到你..
As far as I know you have 2 options: 据我所知,您有两种选择:
1) First download the file and play it locally. 1)首先下载文件并在本地播放。 Like this:
像这样:
NSString *url = [[NSBundle mainBundle] pathForResource:@"cwtvideo" ofType:@"mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
2) Use the HTTP streaming protocol. 2)使用HTTP流协议。 As far as I know HTTP streaming is the only streaming protocol known by the MPMoviePlayerController.
据我所知, HTTP流是MPMoviePlayerController已知的唯一流协议。
Hope this helps. 希望这可以帮助。
Cheers! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.