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

    相关文章

        本文实践自 RayWenderlich、Ali Hafizji 的文章《...
    Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
    第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
        Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
    1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
       Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...