itemFailedToPlayToEnd – MPMoviePlayerController – iOS7

遇到一个奇怪的问题,而更新我的应用程序的iOS 7 。 对于iOS 6 ,没有问题,video总是被加载。 但是,这不是这种情况。

我有一个显示playlistItemsscrollview – 一旦你点击playlistItem ,一个MPMoviePlayerController创build显示播放列表项目(video)。

以下是我相信造成问题的方法:

 - (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

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

这将是两个问题

  1. 问题与url

    a)如果是从api中读取,则必须写入[NSUrl urlwithString:“your url string”];

    //你的urlstring不是youtube的urlstring。

    b)如果是来自bundle的path: [NSUrl fileWithPath:“Your path”];

  2. 与源types有关的问题。

    将scoucetypes设置为任何一个,如果它不起作用,设置为其他typesviceversa

     yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; 

    要么

     yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown; 

我在我的iOS 7版本有相同的问题。 请问您的videourl中是否有空格和数字?

 ie 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 

希望这个build议有一点帮助

对于那些实现本地文件caching的技巧:包括文件扩展名

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

我结束了在一个实际的iPodtesting应用程序 – 它的工作。 与impmoviecontroller的Im初始化没有任何我需要逃脱的空间。 希望这有助于…video不工作在模拟器是扔我

我有这个相同的问题,并通过设置修复

 [MPMoviePlayerViewController.moviePlayer setShouldAutoplay:YES] 

我看到的问题是,电影播放器​​将推到导航控制器,但是当它出现它会消失,我会得到日志_itemFailedToPlayToEnd错误

我有同样的问题。 首先检查你想播放的文件是否存在,然后播放。 在我的情况下我的文件是在文件目录.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"); }