iOS简单视频播放代码
2018-07-20 来源:open-open
1.导入库文件MediaPlayer.framework
2.#import<MediaPlayer/MediaPlayer.h>
// 本地文件
NSURL *url = [[NSBundle mainBundle] URLForResource:@"xxxxxxxxxxxxxxx" withExtension:@"mov"];
// 沙盒中的网络路径 (注意这两种方式的区别)
NSURL *videoUrl = [NSURL fileURLWithPath:..................]];
/**
* 与音频不一样,这个,既可以播放本地视频,也能播放网络资源
*/
self.moviePlayVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
self.moviePlayVC.view.frame = CGRectMake(0, 64, 320, 250);
// 推出视频页面的时候不让自动播放
self.moviePlayVC.moviePlayer.shouldAutoplay = NO;
// 播放器样式,自行选择
self.moviePlayVC.moviePlayer.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:self.moviePlayVC.view];
// 播放器的控制,有点不同,它不是通过协议来实现的,而是通过通知的形式
/**
* MPMoviePlayerWillEnterFullscreenNotification
* MPMoviePlayerDidEnterFullscreenNotification
* MPMoviePlayerWillExitFullscreenNotification
* MPMoviePlayerDidExitFullscreenNotification
* ......具体查看API
*/
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishNotification) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
- (void)didClickPlayBarButtonAction{
//[self.navigationController pushViewController:self.moviePlayVC animated:YES];
[self presentViewController:self.moviePlayVC animated:YES completion:nil];
// 播放
[self.moviePlayVC.moviePlayer play];
}
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:Java字符串验证工具类
最新资讯
热门推荐