Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

itemFailedToPlayToEnd - MPMoviePlayerController - iOS7

Running into a weird issue while updating my app for iOS 7. For iOS 6, there is no problem and the videos are always loaded. However that is not the case here.

I have a scrollview which displays playlistItems - and once you click on the playlistItem, a MPMoviePlayerController is created to show the playlist item (video).

Here is the method that I believe is causing issues:

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

The movie is getting loaded to the 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];
 }

It's weird that this works for iOS 6 but not iOS 7

Here are the NSLog errors when a video does not load/play: <Error>: CGImageCreate: invalid image size: 0 x 0. and: _itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; }

like image 533
OxenBoxen Avatar asked Sep 30 '13 22:09

OxenBoxen


1 Answers

It would be two issues

  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;
    
like image 127
user40910 Avatar answered Oct 20 '22 10:10

user40910