加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – MPMoviePlayerController iO7问题

发布时间:2020-12-14 19:15:11 所属栏目:百科 来源:网络整理
导读:我试图通过MPMoviePlayerController播放存储在我的应用程序文档目录中的视频.我使用以下方法播放视频: NSArray *directoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString *docsDir = [directoryPath obje
我试图通过MPMoviePlayerController播放存储在我的应用程序文档目录中的视频.我使用以下方法播放视频:

NSArray *directoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docsDir = [directoryPath objectAtIndex:0];
int videoNumber = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"videoSaved"];
NSString* videoName = [NSString stringWithFormat:@"video-%d.mov",videoNumber];
NSString *exportPath = [docsDir stringByAppendingPathComponent:videoName];
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath isDirectory:NO];

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:exportUrl];
moviePlayer.fullscreen = YES;
moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieDidExitFullscreen:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

它适用于除iOS7以外的所有iOS版本.在iOS7中,当我尝试播放视频时,我发现了这个错误:

_itemFailedToPlayToEnd: {    kind = 1;    new = 2;    old = 0;}

解决方法

尝试将您的代码更改为:

int videoNumber = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"videoSaved"];

moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:
    [NSURL fileURLWithPath: [[NSBundle mainBundle] 
    pathForResource: [NSString stringWithFormat:@"video-%d",videoNumber] ofType:@"mov"]]];

moviePlayer.fullscreen = YES;
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieDidExitFullscreen:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读