MPMoviePlayerViewController或MPMoviePlayerController播放本地視頻報錯:_itemFailedToPlayToEnd: {kind = 1;new =

MPMoviePlayerViewController或MPMoviePlayerController播放本地視頻報錯:

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

}

cocos2dx videoview ios播放錯誤問題

在網上搜了很多解決方法都沒解決掉。後來發現是url錯誤。

錯誤代碼:

[objc] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. NSString *path = [[NSBundle mainBundle] pathForResource@"test.MOV" ofType: nil nil];  
  2.   
  3. MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL URLWithString: path]];  
  4. mpvc.moviePlayer.fullscreen = YES;  
  5. mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;  

正確代碼:

[objc] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. NSString *path = [[NSBundle mainBundle] pathForResource@"test.MOV" ofType: nil nil];  
  2.   
  3. MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL fileURLWithPath: path]];  
  4. mpvc.moviePlayer.fullscreen = YES;  
  5. mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;  

區別僅僅在創建url實例所使用的類方法:

[objc] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. [NSURL URLWithString: path]  
生成的URL是:/var/mobile/Applications/3C78D5FF-8953-4AC2-BF5A-293261A5468E/TestVideo.app/test.MOV 

[objc] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. [NSURL fileURLWithPath: path]  
生成的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 = [[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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章