How to prevent my MPMoviePlayerController from turning black when returned from a webView containing an iOS YouTube video

Here is the context: NavigationController -> FirstViewController -> SecondViewController

FirstViewController displays MPMoviePlayerController inline and buttons to navigate to SecondViewController. This MPMoviePlayerController reads a local .m4v file.

SecondViewController displays a UIWebView with web pages containing YouTube videos.

Here are the steps:

  • user read video on FirstViewController (works great)
  • the user clicks one of the buttons to go to the SecondViewController
  • the user clicks one of the YouTube videos to play in inline mode in the webView (works great too)
  • user clicks back button in NavigationItem

The problem arises at the moment:

When the user comes back from the SecondViewController, the MPMoviePlayerController is black.

I've tried using prepareToPlay on MoviePlayer in viewWillAppear and / or viewDidAppear. In both cases, I got a good result in half a second, and then the MoviePlayer view went black again. I think when the viewDidUnload is called in the SecondViewController something happens that gives a shortcut to the MoviePlayer web skin.

Any idea on how to fix the problem?

Note. this is only visible on the device because the videos are not displayed in the UIWebView in the simulator. I tried to reproduce it with another MPMoviePlayerController in the second view, but by putting prepareToPlay in viewDidAppear, it solved ...

Note 2: This issue only appears on iPad. I tried to play it on iPhone, but YouTube player won't play video in embedded mode on iPhone ...

+3


source to share


1 answer


There shouldn't be any movie code. Just put your video in your webview code, it will work fine.



0


source







All Articles