4

When I try to initiate a video to play (via YouTube) in a UIWebView, the video opens, then the debugger says:

[MPAVController] Autoplay: Enabling autoplay
[MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)

Here's a similar question: MPMoviePlayerController stops playing after a few seconds

My only problem is that with a UIWebView, I can't set up an MPMoviePlayerController to prepareToPlay. At least not as far as my knowledge goes. If anyone can help fix this problem, that would be amazing!

Community
  • 1
  • 1
Encephalon
  • 153
  • 2
  • 12
  • When using a web view to play video, the class that handles the playback is **not** `MPMoviePlayerController` even though the interface looks the same. – Till Sep 30 '12 at 11:37
  • Ok. So how can I fix this issue then? – Encephalon Sep 30 '12 at 11:45
  • @Encephalon can u tell me what actually your problem. if your player automatically closes or any other problem. – Kamar Shad Oct 12 '12 at 06:11

2 Answers2

10

I have also faced a similar problem in iOS 6. The reason behind this is that when YouTube video is played in another than iOS6 version viewWillDisappear method is not called up. But in iOS6 this method is called up every time whenever a YouTube video is played. It may be an OS level bug but I am not sure about it.

However, I have fixed it and the steps are as below.

Add full-screen entry and exit notification, use a Boolean property, and updates it accordingly.

// Notification when the player moves to full screen

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeVideofullScreen:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];

// Notification when the player exit from full screen.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeVideoExit:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
 - (void)youTubeVideofullScreen:(id)sender {
      //Update flag.
      isFullscreen = TRUE;
 }

 - (void)youTubeVideoExit:(id)sender {
        //Update flag.
        isFullscreen = FALSE;
  }

 - (void)viewWillDisappear:(BOOL)animated {
    //Now you can use that flag and avoid the code execution which is interrupting the video
    
      if(!isFullscreen) {
       [super viewWillDisappear:animated]; 

       }
  }

Hope it is helpful to you.

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56
  • not working for me :( I applied this to both `viewWillDisappear` and `viewDidDisappear` – Nikita P Jan 04 '13 at 10:01
  • @NikitaP I don't Your Code how you doing same.you should ask a question separately rather than here...!!! – Kamar Shad Jan 04 '13 at 10:32
  • @Kamarshad: please refer: http://stackoverflow.com/questions/14154137/video-embedded-on-a-link-not-working-on-uiwebview-with-ios6-simulator-or-device#comment19606770_14154137 – Nikita P Jan 04 '13 at 10:35
  • @Kamarshad i want to close this default AVPlayer when this notification called UIMoviePlayerControllerDidEnterFullscreenNotification . – Ravi Sharma Apr 23 '13 at 07:49
  • How can i rotate movie player? – Nam Vu Jun 13 '13 at 07:15
4

I just had this very same issue in one of our apps. Turns out we were setting the UIWebView's HTML to an empty string in -(void)viewWillDisappear. Apparently this method is now being called in iOS 6 when displaying a fullscreen video from an UIWebView, so that's probably where your issue comes from.

Ecco
  • 1,323
  • 1
  • 11
  • 15