Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 602
Encephalon Avatar asked Dec 04 '22 01:12

Encephalon


1 Answers

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.

like image 94
Kamar Shad Avatar answered Dec 05 '22 13:12

Kamar Shad