草庐IT

iphone - itemFailedToPlayToEnd - MPMoviePlayerController - iOS7

coder 2023-07-27 原文

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; }

最佳答案

这是两个问题

  1. 网址有问题

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

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

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

  2. 源类型问题。

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

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
    

关于iphone - itemFailedToPlayToEnd - MPMoviePlayerController - iOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19104728/

有关iphone - itemFailedToPlayToEnd - MPMoviePlayerController - iOS7的更多相关文章

随机推荐