从iOS中的Internet URL或本地文件播放.mp4或.mov视频?

时间:2014-05-07 08:02:17

标签: ios objective-c

如何从iOS中的Internet URLlocal file播放 .mp4 .mov 视频?

我如何在集合视图控制器中添加几个视频?

2 个答案:

答案 0 :(得分:5)

试试这个(MPMoviePlayerController):

NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pathVideo = [documentsDirectory stringByAppendingPathComponent:@"MyVideo.mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:pathVideo];
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[self.moviePlayer setShouldAutoplay:YES];
[self.moviePlayer setContentURL:movieURL.absoluteURL];
[self.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
[self.moviePlayer setControlStyle:MPMovieControlModeDefault];
[self.moviePlayer setFullscreen:NO];

[self.moviePlayer setScalingMode:MPMovieScalingModeNone];
self.moviePlayer.view.frame = CGRectMake(40, 40, 240, 350);
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];

答案 1 :(得分:1)

使用MPMoviePlayerController

  

电影播放器​​(MPMoviePlayerController类型)管理播放   来自文件或网络流的电影。在视图中进行播放   由电影播放器​​拥有,可以全屏或内联播放。   您可以将电影播放器​​的视图合并到所拥有的视图层次结构中   通过您的应用程序,或使用MPMoviePlayerViewController对象来管理   为您呈现。

文档:https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html