技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong
如何播放视频
•iOS提供了叫做MPMoviePlayerController、MPMoviePlayerViewController的两个类,可以用来轻松播放视频
ØYouTobe就是用MPMoviePlayerController实现的
ØMPMoviePlayerViewController只能全屏播放视频
•上述两个类都定义在了MediaPlayer框架中
MPMoviePlayerController支持的格式
•MPMoviePlayerController继承自NSObject,它内部有个view用来展示视频内容,
添加其他控制器的view上面即可显示•MPMoviePlayerController可以播放的视频格式有以下两种:ØH.264
ØMPEG-4 Part 2 video
•支持的文件拓展名为:avi,mkv,mov,m4v,mp4等
•可以到苹果官网:http://support.apple.com/kb/HT1425下载一些用来测试的视频文件,文件都比较小
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong
MPMoviePlayerController-01-加载资源
//加载视频资源
NSString*urlString = [[NSBundlemainBundle]pathForResource:@"sample_iTunes"ofType:@"mov"];
NSURL*url = [NSURLfileURLWithPath:urlString]; //创建播放器
_player= [[MPMoviePlayerControlleralloc]initWithContentURL:url];
MPMoviePlayerController-02-显示
//设置尺寸_player.view.frame=self.view.bounds;
_player.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
//添加到控制器的view上[self.viewaddSubview:_player.view]; //播放[_playerplay];
MPMoviePlayerController-03-添加通知监听
//监听播放状态的改变
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(videoStateChange)name:MPMoviePlayerPlaybackStateDidChangeNotificationobject:_player];
//监听播放器结束全屏
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(exitFullscreen)name:MPMoviePlayerDidExitFullscreenNotificationobject:_player];
//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3498500.html
MPMoviePlayerController其他属性
•是否要自动播放
@property(nonatomic)BOOLshouldAutoplay;
•全屏显示
@property(nonatomic,getter=isFullscreen)BOOLfullscreen;
- (void)setFullscreen:(BOOL)fullscreen animated: (BOOL)animated;
•截取视频中的图片
- (void)requestThumbnailImagesAtTimes:(NSArray*)playbackTimes timeOption:(MPMovieTimeOption)option;
MPMoviePlayerViewController
•MPMoviePlayerViewController继承自UIViewController,它内部封装了一个
MPMoviePlayerController
•MPMoviePlayerViewController只能全屏播放
•简单使用:
//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3498500.html
本文对应pdf文档下载链接,猛戳-->: |
本文对应pdf文档下载链接,猛戳—>:https://www.evernote.com/shard/s227/sh/8754b8a6-6f11-4f71-a914-f9ac90e7f56e/ac0df8a6c105965e961cf1277fc1b433
//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3498500.html
来源:https://www.cnblogs.com/ChenYilong/p/3498500.html