MPMoviePlayerViewController 和 MPMoviePlayerController

来源:互联网 发布:监控端口号怎么查看 编辑:程序博客网 时间:2024/04/29 14:50
ios播放视频文件一般使用 MPMoviePlayerViewController 和 MPMoviePlayerController。这两者的区别就是MPMoviePlayerViewController里面包含了一个MPMoviePlayerController先说MPMoviePlayerController首先要包含 #import <MediaPlayer/MediaPlayer.h>头文件和MediaPlayer.framework。- (void)createMPPlayerController:(NSString *)sFileNamePath {  NSURL *movieURL = [NSURL fileURLWithPath:sFileNamePath]; MPMoviePlayerController *movewController =[[MPMoviePlayerController alloc] initWithContentURL:movieURL]; [movewController prepareToPlay]; [self.view addSubview:movewController.view];//设置写在添加之后   // 这里是addSubView movewController.shouldAutoplay=YES; [movewController setControlStyle:MPMovieControlStyleDefault]; [movewController setFullscreen:YES]; [movewController.view setFrame:self.view.bounds]; 这里注册相关操作的通知 [[NSNotificationCenter defaultCenter] addObserver:self                                             selector:@selector(movieFinishedCallback:)                                                 name:MPMoviePlayerPlaybackDidFinishNotification                                               object:moveViewController.movewController]; //播放完后的通知 [movewController release];}-(void)movieFinishedCallback:(NSNotification*)notify {    MPMoviePlayerController* theMovie = [notifyobject];    [[NSNotificationCenterdefaultCenter] removeObserver:self                                                    name:MPMoviePlayerPlaybackDidFinishNotification                                                  object:theMovie];    [theMovie.view removeFromSuperview];    [theMovie release];}//////////////////////////////// end2.介绍下MPMoviePlayerViewController。 注意:MPMoviePlayerViewController 必须 presentMoviePlayerViewControllerAnimated方式添加,否则Done按钮是不会响应通知MPMoviePlayerPlaybackDidFinishNotification事件的;- (void)createMPPlayerController:(NSString *)sFileNamePath {    MPMoviePlayerViewController *moviePlayer =[[MPMoviePlayerViewControlleralloc] initWithContentURL:[NSURLfileURLWithPath:sFileNamePath]];    [moviePlayer.moviePlayerprepareToPlay];    [selfpresentMoviePlayerViewControllerAnimated:moviePlayer]; // 这里是presentMoviePlayerViewControllerAnimated    [moviePlayer.moviePlayersetControlStyle:MPMovieControlStyleFullscreen];    [moviePlayer.view setBackgroundColor:[UIColor clearColor]];    [moviePlayer.view setFrame:self.view.bounds];    [[NSNotificationCenterdefaultCenter] addObserver:self                                             selector:@selector(movieFinishedCallback:)                                                 name:MPMoviePlayerPlaybackDidFinishNotification                                               object:moviePlayer.moviePlayer];    [moviePlayer release];}-(void)movieStateChangeCallback:(NSNotification*)notify  {   //点击播放器中的播放/ 暂停按钮响应的通知}-(void)movieFinishedCallback:(NSNotification*)notify{   // 视频播放完或者在presentMoviePlayerViewControllerAnimated下的Done按钮被点击响应的通知。    MPMoviePlayerController* theMovie = [notifyobject];    [[NSNotificationCenterdefaultCenter] removeObserver:self                                                    name:MPMoviePlayerPlaybackDidFinishNotification                                                  object:theMovie];    [selfdismissMoviePlayerViewControllerAnimated];}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 魅族手机音量小怎么办 魅族mx5指纹解锁失灵怎么办 魅族手机费电快怎么办 魅族mx4pro玩王者荣耀卡怎么办 魅蓝5s玩游戏卡怎么办 魅蓝s6玩游戏卡怎么办 OPPO王者荣耀对局闪退怎么办 魅族手机太慢怎么办 魅蓝5信号不好怎么办 魅蓝数据网速慢怎么办 魅族联通网速慢怎么办 魅族手机wifi信号弱怎么办 魅蓝e2信号差怎么办 魅蓝e2gps信号弱怎么办 魅族网络信号差怎么办 魅族手机gps信号弱怎么办 魅族手机突然没有信号怎么办 魅族手机流量信号不好怎么办 魅族手机wifi信号差怎么办 魅族5s信号不好怎么办 魅族mx5的双击不亮屏怎么办 魅族mx5返回键失灵怎么办 电信苹果3g网速慢怎么办 魅蓝6开不了机怎么办 手机应用被锁了怎么办 魅族电池不耐用怎么办 魅族mx6现在很卡怎么办 魅族e2手机屏幕背景黑色怎么办 魅族x6手机锁了怎么办 360n5返回键失灵怎么办 360n5返回键不好用怎么办 魅族手机锁屏怎么办 魅族手机锁住了怎么办 手机己锁定怎么办魅族 魅蓝u10触屏没反应怎么办 魅蓝e2手机锁定怎么办 苹果手机声音键坏了怎么办 一加6的屏幕问题怎么办 魅蓝note6卡顿怎么办 苹果4s内屏坏了怎么办 魅族mx6一直重启怎么办