项目无法播放完毕 - MPMoviePlayerController - iOS7

14

当我更新我的应用程序以适用于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; }


2
我在iOS7上遇到了类似的问题,也收到了错误代码-11828,有人找到了解决方案吗? - Gal Blank
你尝试过监听 MPMoviePlayerPlaybackDidFinishNotification 通知吗?它可能会包含一个错误对象 - nverinaud
6个回答

4
这将涉及两个问题。
  1. Problem with url

    a) If it is fetching from api's you have to write ,[NSUrl urlwithString:"your url string"];

    // your url string does not be youtube url string.

    b) If it is from bundle path : [NSUrl fileWithPath:"Your path"];

  2. Problem with Source type.

    Set scouce type to any one , if it not works set to other type viceversa

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    

    or

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
    

2

我在我的iOS 7构建中遇到了同样的问题。请问您的视频URL中是否有空格和数字?

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

希望这些建议能够对你有所帮助。

1
最终我在实际的iPad上测试了该应用程序 - 看起来它可以工作。我使用mpmoviecontroller初始化的URL没有任何需要转义的空格。希望这可以帮到你...视频在模拟器上无法工作,这让我感到困惑。 - OxenBoxen
我遇到了一个相关的错误。从我的文件名中删除数字就解决了问题。感谢这个想法。 - Holger Frohloff

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

0

我遇到了同样的问题。 首先检查您想要播放视频的文件是否存在,然后再播放。 在我的情况下,我的文件在文档目录中。

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

0

我遇到过这个问题,解决方法是设置

[MPMoviePlayerViewController.moviePlayer setShouldAutoplay:YES]

我遇到的问题是电影播放器会推到导航控制器上,但当它出现时就会消失,然后在日志中会得到“_itemFailedToPlayToEnd”错误。

0

最终我在实际的iPod上测试了该应用程序 - 它可以正常工作。我使用mpmoviecontroller初始化的URL没有任何需要转义的空格。希望这可以帮到你...视频在模拟器上无法工作,这让我感到困惑。


2
这应该是一个注释。 - Atul O Holic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接