加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

MPMoviePlayerViewController或MPMoviePlayerController播放本地

发布时间:2020-12-14 20:37:09 所属栏目:百科 来源:网络整理
导读:MPMoviePlayerViewController或MPMoviePlayerController播放本地视频报错: _itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; } cocos2dx videoview ios播放错误问题 在网上搜了很多解决方法都没解决掉。 后来发现是url错误。 错误代码: [objc] view

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

      (编辑:李大同)

      【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读