ios 最简单的视频播放器
2016-07-26 15:40
555 查看
#import "ViewController.h" #import <MediaPlayer/MediaPlayer.h> @interface ViewController () @property (nonatomic,strong) MPMoviePlayerController *moviePlayer;//视频播放控制器 @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self.moviePlayer play]; [self addNotification]; } -(void)dealloc{ //移除所有通知监控 [[NSNotificationCenter defaultCenter] removeObserver:self]; } -(MPMoviePlayerController *)moviePlayer{ if (!_moviePlayer) { NSString *urlStr=[[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@"resource.bundle/war3end.mp4"]; NSURL *url=[NSURL fileURLWithPath:urlStr]; _moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:url]; _moviePlayer.view.frame=self.view.bounds; _moviePlayer.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; [self.view addSubview:_moviePlayer.view]; } return _moviePlayer; } -(void)addNotification{ NSNotificationCenter *notificationCenter=[NSNotificationCenter defaultCenter]; [notificationCenter addObserver:self selector:@selector(mediaPlayerPlaybackStateChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer]; [notificationCenter addObserver:self selector:@selector(mediaPlayerPlaybackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer]; } -(void)mediaPlayerPlaybackStateChange:(NSNotification *)notification{ switch (self.moviePlayer.playbackState) { case MPMoviePlaybackStatePlaying: NSLog(@"正在播放..."); break; case MPMoviePlaybackStatePaused: NSLog(@"暂停播放."); break; case MPMoviePlaybackStateStopped: NSLog(@"停止播放."); break; default: NSLog(@"播放状态:%li",self.moviePlayer.playbackState); break; } } -(void)mediaPlayerPlaybackFinished:(NSNotification *)notification{ NSLog(@"播放完成.%li",self.moviePlayer.playbackState); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 买视频送图书-五月活动
- DVI 视频接口图文解析
- C#实现语音视频录制-附demo源码
- 编写C++程序使DirectShow进行视频捕捉
- AnyChat的视频会议程序实例详解
- C#调用mmpeg进行各种视频转换的类实例
- C#获取视频某一帧的缩略图的方法
- 基于jQuery的网页影音播放器jPlayer的基本使用教程
- 显示youtube视频缩略图和Vimeo视频缩略图代码分享
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结