title: itemFailedToPlayToEnd - MPMoviePlayerController - iOS7
body: <p>Running into a weird issue while updating my app for <code>iOS 7</code>. For <code>iOS 6</code>, there is no problem and the videos are always loaded. However that is not the case here.</p>
  
  <p>I have a <code>scrollview</code> which displays <code>playlistItems</code> - and once you click on the <code>playlistItem</code>, a <code>MPMoviePlayerController</code> is created to show the playlist item (video).</p>
  
  <p>Here is the method that I believe is causing issues:</p>
  
  <pre><code>- (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];
  }
  </code></pre>
  
  <p>The movie is getting loaded to the <code>MovieContainerView</code>.</p>
  
  <pre><code>- (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];
   }
  </code></pre>
  
  <p>It's weird that this works for <code>iOS 6</code> but not <code>iOS 7</code></p>
  
  <p>Here are the NSLog errors when a video does not load/play: <code>&lt;Error&gt;: CGImageCreate: invalid image size: 0 x 0.</code>  and: <code>_itemFailedToPlayToEnd: {
      kind = 1;
      new = 2;
      old = 0;
  }
  </code></p>