iOS:使用MPMoviePlayerController播放带URL的远程视频

时间:2013-05-29 06:47:41

标签: iphone objective-c xcode mpmovieplayercontroller

NSURL *url= [NSURL URLWithString:@"http://www.dailymotion.com/video/x109z02"];
MPMoviePlayerController  *theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
theMoviPlayer.scalingMode = MPMovieScalingModeFill;
theMoviPlayer.view.frame = CGRectMake(0, 60, 320, 350);
[self.view addSubview:theMoviPlayer.view];
[self.theMoviPlayer play];

框架也在.h文件中添加和导入,但视频不能在iphone中播放(互联网连接也可以)

2 个答案:

答案 0 :(得分:2)

NSURL *url   = [NSURL URLWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
                                          initWithContentURL:url];

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

_moviePlayer.controlStyle   = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];

答案 1 :(得分:1)

使用UIWebView,这是一种非常简单易行的方法。