iOS 在应用中播放本地视频文件

可以使用MPMoviePlayerController来播放本地视频文件

1.添加 Mediaplayer framework 并且在viewcontroller中#import <MediaPlayer/MediaPlayer.h> 

2. 把视频文件拖拽到xcode中

3. 获取文件存放的路径

NSString*thePath=[[NSBundle mainBundle] pathForResource:@"yourVideo" ofType:@"MOV"];
NSURL*theurl=[NSURL fileURLWithPath:thePath];

4. 用该路径初始化moviePlayer

self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:theurl];
[self.moviePlayer.view setFrame:CGRectMake(40, 197, 240, 160)];
[self.moviePlayer prepareToPlay];
[self.moviePlayer setShouldAutoplay:NO]; // And other options you can look through the documentation.
[self.view addSubview:self.moviePlayer.view];

5. 添加playback后需要做什么操作的控制

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
//playBackFinished will be your own method.


翻译自:

http://stackoverflow.com/a/9802543/3458781



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。