博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
本地视频播放-ios
阅读量:5227 次
发布时间:2019-06-14

本文共 2197 字,大约阅读时间需要 7 分钟。

// 视频播放-(void)playMovie{    self.navigationItem.rightBarButtonItem.enabled = YES;        self.movieName = @"1305178253912757X4VMU00207002";    self.folderName = @"1-11";    //在VideoFolder文件夹下建立子文件夹    NSFileManager *fm = [[NSFileManager alloc]init];    NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];    NSString *folderPath = [docs stringByAppendingPathComponent:[NSString stringWithFormat:@"VideoFolder/%@/%@.mp4",self.folderName,self.movieName]];    BOOL exists = [fm fileExistsAtPath:folderPath];    if (exists) {        NSURL *urls = [NSURL fileURLWithPath:folderPath];        movie = [[MPMoviePlayerController alloc]initWithContentURL:urls];        movie.controlStyle = MPMovieControlStyleDefault;        [movie  prepareToPlay];        [movie.view setFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height-60)];        movie.movieSourceType = MPMovieSourceTypeFile;        movie.initialPlaybackTime = -1;        [self.view addSubview:movie.view];        //注册一个播放结束的通知        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie];        [movie play];    }    [fm release];    }//当视频播放结束的时候关闭视频-(void)movieFinishedCallback:(NSNotification*)notify{    //视频播放对象    MPMoviePlayerController* theMovie = [notify object];    //销毁播放通知    [[NSNotificationCenter defaultCenter] removeObserver:self                                                    name:MPMoviePlayerPlaybackDidFinishNotification                                                  object:theMovie];    [theMovie.view removeFromSuperview];    [movie.view removeFromSuperview];    // 释放视频对象    //    [movie release];    [theMovie release];}//手动关闭视频-(void)closeMovie{    self.navigationItem.rightBarButtonItem.enabled = NO;        [[NSNotificationCenter defaultCenter] removeObserver:self                                                    name:MPMoviePlayerPlaybackDidFinishNotification                                                  object:movie];    [movie.view removeFromSuperview];}

 

转载于:https://www.cnblogs.com/jiackyan/archive/2013/05/31/3109790.html

你可能感兴趣的文章
初识lua
查看>>
我是插件狂人,jDuang,jValidator,jModal,jGallery
查看>>
张季跃 201771010139《面向对象程序设计(java)》第四周学习总结
查看>>
如何解除循环引用
查看>>
android中fragment的使用及与activity之间的通信
查看>>
字典【Tire 模板】
查看>>
jquery的contains方法
查看>>
python3--算法基础:二分查找/折半查找
查看>>
Perl IO:随机读写文件
查看>>
Perl IO:IO重定向
查看>>
转:基于用户投票的排名算法系列
查看>>
WSDL 详解
查看>>
[转]ASP数组全集,多维数组和一维数组
查看>>
C# winform DataGridView 常见属性
查看>>
逻辑运算和while循环.
查看>>
Nhiberate (一)
查看>>
c#后台计算2个日期之间的天数差
查看>>
安卓开发中遇到的小问题
查看>>
ARTS打卡第3周
查看>>
linux后台运行和关闭SSH运行,查看后台任务
查看>>