MPMoviePlayerViewController或MPMoviePlayerController播放本地視頻報錯:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
cocos2dx videoview ios播放錯誤問題
在網上搜了很多解決方法都沒解決掉。後來發現是url錯誤。
錯誤代碼:
- NSString *path = [[NSBundle mainBundle] pathForResource: @"test.MOV" ofType: nil 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 nil];
- MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL fileURLWithPath: path]];
- mpvc.moviePlayer.fullscreen = YES;
- mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
區別僅僅在創建url實例所使用的類方法:
- [NSURL URLWithString: path]
- [NSURL fileURLWithPath: path]
看出區別來了吧。
上面是別人的博客內容
修改一下cocos/ui/UIVideoPlayerIOS.mm 文件中的-(void) setURL:(int)videoSource :(std::string &)videoUrl函數中的
if (videoSource == 1) {
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@(videoUrl.c_str())]];
self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
} else {
NSString *path = [UIVideoViewWrapperIos fullPathFromRelativePath:@(videoUrl.c_str())];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
}
改爲
if (videoSource == 1) {
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@(videoUrl.c_str())]];
self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
} else {
NSString *path = [[NSBundle mainBundle] pathForResource:@(videoUrl.c_str()) ofType: nil];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
}
沒有修改cocos2dx源碼前視頻都可以播放,後來就不知道怎麼不能夠播放了報上面的錯誤。
不過修改之後就可以播放啦
參考 http://blog.csdn.net/realhector/article/details/24580781