【问题标题】:itemFailedToPlayToEnd - MPMoviePlayerController - iOS7itemFailedToPlayToEnd - MPMoviePlayerController - iOS7
【发布时间】:2013-10-06 22:28:41
【问题描述】:

在为iOS 7 更新我的应用程序时遇到了一个奇怪的问题。对于iOS 6,没有问题,视频总是被加载。但是这里不是这样。

我有一个scrollview,它显示playlistItems - 一旦你点击playlistItem,就会创建一个MPMoviePlayerController 来显示播放列表项(视频)。

这是我认为会导致问题的方法:

- (void) play:(NSInteger)itemId withAutostart:(BOOL)autostart {

  // remember whether it is in fullscreen or not to restore for the next playlist item
  self.playerInFullscreen = self.player.isFullscreen;

  if (player != nil) {
    [self.player setFullscreen:NO animated:NO];
    [self stopListeningPlaybackFinishedEvents];
    [player stop];
    [self startListeningPlaybackFinishedEvents];
  }

  PlaylistItem * pi = [dbHelper getPlaylistItem:itemId];
  NSURL *movieURL = [pi getMovieUrl];

  if (DELEGATE.useSSL) {

    NSURLCredential *credential = [[NSURLCredential alloc]
                                 initWithUser: DELEGATE.username
                                 password: DELEGATE.password
                                 persistence: NSURLCredentialPersistenceForSession];

    NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
                                           initWithHost: [movieURL host]
                                           port: 80
                                           protocol: [movieURL scheme]
                                           realm: [movieURL host]
                                           authenticationMethod: NSURLAuthenticationMethodHTTPBasic];

    [[NSURLCredentialStorage sharedCredentialStorage]
     setDefaultCredential: credential
     forProtectionSpace: protectionSpace];

    [protectionSpace release];
    [credential release];
  }


  MPMoviePlayerController * temp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [temp prepareToPlay];

  self.player =  temp;
  [temp release];

    player.shouldAutoplay = autostart;
  player.view.frame = movieViewContainer.bounds; 
  [movieViewContainer addSubview:player.view];

    NSLog(@"movie added to subview");

  [player setFullscreen:self.playerInFullscreen animated:NO];
  [self.view setNeedsDisplay];
}

电影正在加载到MovieContainerView

- (void)playlistItemSelected:(NSInteger)itemId withAutostart:(BOOL) autostart {
  for(UIView *subview in [thumbsScrollView subviews]) {
    if ([subview isKindOfClass:[PlaylistItemView class]] == YES ) {

      PlaylistItemView *piv = ((PlaylistItemView *) subview);
      [piv setCurrent: piv.playlistItem._id == itemId];

      if (piv.playlistItem._id == itemId) {
        [self ensurePlaylistItemViewVisible:piv];
      }
    }
  }
  [[movieViewContainer subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
  self.currentPlaylistItem = [dbHelper getPlaylistItem:itemId];
  [self updateMetadataArea:itemId];

  if ([_currentPlaylistItem.type isEqual:VIDEO_TYPE]) {
    self.zoomButtonOut.hidden = YES;
    self.zoomButtonIn.hidden  = YES;

    [self play:itemId withAutostart:autostart];
  }
  else {
     [self.player pause];
    _zoomButtonIn.alpha = ZOOM_BUTTON_ALPHA;
    _zoomButtonOut.alpha = ZOOM_BUTTON_ALPHA;
    [self showPDFandImage:_currentPlaylistItem];
  }
  [self scrollViewDidEndDecelerating:nil];
 }

奇怪的是,这适用于iOS 6,但不适用于iOS 7

以下是视频无法加载/播放时的 NSLog 错误:<Error>: CGImageCreate: invalid image size: 0 x 0. 和:_itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; }

【问题讨论】:

  • 我只在 iOs7 上遇到了类似的问题,我也收到错误 -11828 有人找到解决方案了吗?
  • 您是否尝试收听MPMoviePlayerPlaybackDidFinishNotification 通知?可能是contains an error object.

标签: iphone ios ios7 mpmovieplayercontroller


【解决方案1】:

这将是两个问题

  1. 网址有问题

    a) 如果它是从 api 获取的,你必须写,[NSUrl urlwithString:"your url string"];

    // 你的 url 字符串不是 youtube url 字符串。

    b) 如果它来自包路径:[NSUrl fileWithPath:"Your path"];

  2. Source 类型有问题。

    将 scouce 类型设置为任何一种,如果不起作用,则设置为其他类型,反之亦然

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
    

【讨论】:

    【解决方案2】:

    我的 iOS 7 版本也遇到了同样的问题。请问您的视频网址中是否有空格和数字?

    i.e. my url was something like "video title 5.2.5.mov" and when I escaped the string using the NSUTF8StringEncoding, the result was "video%20title%205.2.5.mov" and it didn't work.
    
    I tried changing the movie url to video_title_5_2_5.mov" and it loaded fine
    

    希望这个建议能有所帮助

    【讨论】:

    • 我最终在实际的 ipad 上测试了该应用程序 - 瞧,它确实有效。使用 mpmoviecontroller 初始化的 url 没有我需要转义的任何空格。希望这会有所帮助...视频无法在模拟器上运行,这让我很失望
    • 我遇到了相关错误。从我的文件名中删除数字是治疗方法。感谢这个想法。
    【解决方案3】:

    实现本地文件缓存的提示:包含文件扩展名

    我的一个应用程序中有一个本地下载缓存,它不区分文件类型 [无论好坏],导致文件没有与之关联的类型。当我将文件从服务器直接提供到电影控制器时,文件可以正常播放,但是当它在本地存储到路径中时: [AppDocumentsDirectory]/123(没有扩展名)它无法播放。当我将文件存储为 123.mp4 时,它成功了。

    【讨论】:

      【解决方案4】:

      我最终在一个实际的 ipod 上测试了该应用程序 - 它工作正常。使用 mpmoviecontroller 初始化的 url 没有我需要转义的任何空格。希望这会有所帮助...视频无法在模拟器上运行,这让我很失望

      【讨论】:

      • 这应该是一条评论。
      【解决方案5】:

      我也遇到了同样的问题,通过设置解决了

      [MPMoviePlayerViewController.moviePlayer setShouldAutoplay:YES]
      

      我看到的问题是电影播放器​​会推送到导航控制器上,但是当它出现时它会消失,并且我会在日志中收到 _itemFailedToPlayToEnd 错误

      【讨论】:

        【解决方案6】:

        我遇到了同样的问题。 首先检查您要播放该视频的文件是否存在。然后播放。 就我而言,我的文件位于文档目录 .so 中

            BOOL hasVideoFile= [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@",[self getDocumentDirectory] videoFileName]];
            if (!hasVideoFile) {
                //No video found
                NSLog(@"Video file doesn't exists in this directory");
            }
        

        【讨论】:

          猜你喜欢
          • 2014-05-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多