MPMoviePlayerViewController或MPMoviePlayerController播放本地视频报错:_itemFailedToPlayToEnd: {kind = 1;new =

前端之家收集整理的这篇文章主要介绍了MPMoviePlayerViewController或MPMoviePlayerController播放本地视频报错:_itemFailedToPlayToEnd: {kind = 1;new =前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

MPMoviePlayerViewController或MPMoviePlayerController播放本地视频报错:

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

}

cocos2dx videoview ios播放错误问题

在网上搜了很多解决方法都没解决掉。后来发现是url错误

错误代码

[objc] view plain copy
  1. NSString*path=[[NSBundlemainBundle]pathForResource:@"test.MOV"ofType:nilnil];
  2. MPMoviePlayerViewController*mpvc=[[MPMoviePlayerViewControlleralloc]initWithContentURL:[NSURLURLWithString:path]];
  3. mpvc.moviePlayer.fullscreen=YES;
  4. mpvc.moviePlayer.movieSourceType=MPMovieSourceTypeFile;

正确代码

    fileURLWithPath:区别仅仅在创建url实例所使用的类方法

    [NSURLpath]
生成的URL是:/var/mobile/Applications/3C78D5FF-8953-4AC2-BF5A-293261A5468E/TestVideo.app/test.MOV

    生成的URL是:file:///var/mobile/Applications/3C78D5FF-8953-4AC2-BF5A-293261A5468E/TestVideo.app/test.MOV

    看出区别来了吧。

    上面是别人的博客内容

    修改一下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 =[[NSBundlemainBundle]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

    原文链接:https://www.f2er.com/cocos2dx/343963.html

    猜你在找的Cocos2d-x相关文章