MPMoviePlayerViewController或MPMoviePlayerController播放本地视频报错:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
在网上搜了很多解决方法都没解决掉。后来发现是url错误。
错误代码:
NSString *path = [[NSBundle mainBundle] pathForResource: @"test.MOV" ofType: nil];
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL URLWithString: path]];
mpvc.moviePlayer.fullscreen = YES;
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
正确代码:
NSString *path = [[NSBundle mainBundle] pathForResource: @"test.MOV" ofType: nil];
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL fileURLWithPath: path]];
mpvc.moviePlayer.fullscreen = YES;
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
区别仅仅在创建url实例所使用的类方法:
[NSURL URLWithString: path]
生成的URL是:/var/mobile/Applications/3C78D5FF-8953-4AC2-BF5A-293261A5468E/TestVideo.app/test.MOV
[NSURL fileURLWithPath: path]
生成的URL是:file:///var/mobile/Applications/3C78D5FF-8953-4AC2-BF5A-293261A5468E/TestVideo.app/test.MOV
看出区别来了吧。
希望对你有所帮助。如果有帮助请回复让我知道。