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

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

问题描述:

如何从互联网网址或 .mp4 或 .mov 视频iOS中的c $ c>本地文件?

How can I play a .mp4 or .mov video from either an Internet URL or a local file in iOS?

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

And how I can add several of videos in the collection view controller?

试试这个(MPMoviePlayerController):

Try this (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];