Encephalon
Encephalon

Reputation: 153

UIWebView Movie Player getting dismissed iOS 6 bug

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!

Upvotes: 4

Views: 7036

Answers (2)

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

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.

Upvotes: 10

Ecco
Ecco

Reputation: 1393

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.

Upvotes: 4

Related Questions