MPMoviePlayerController breaks/stops after going to fullscreen in iOS6

19,835

Solution 1

I solved it by myself. As I add the Movie Player as a subview to a container view I don't need to use the actual view controller created with the MPMoviePlayerViewController which is intended to be used to present it modally or in some other vc hierarchy.

For the single purpose of having a Movie Player view that can be added to some other view as a subview the MPMoviePlayerController's view property is sufficient.

Until iOS 6 both worked but iOS 6 seems to differ in terms of ressource management/lifetime.

The example project is updated with working code.

Solution 2

Are you stopping the video in viewWillDisappear: or viewDidDisappear:? Those methods get called when a video enters fullscreen on iOS 6, but not on any earlier iOS versions (a report has been filed at Open Radar for this "bug"). I posted this temporary solution on a similar question:

My temporary solution until the bug is fixed is to check the player's fullscreen Boolean value in viewWillDisappear: and/or viewDidDisappear:. If it returns YES, the movie is entering fullscreen mode and you should refrain from doing anything that might interrupt it.

Solution 3

I've solved this problem with a different approach. Since the main reason of the problem is iOS 6 calling viewWillDisappear: and/or viewDidDisappear: methods. I thought that maybe iOS also calling the same methods of MPMoviePlayerViewController. So I've created a Category for MPMoviePlayerViewController and implemented viewWillDisappear: and/or viewDidDisappear: methods. Interestingly it works. (by the way this is not recommended by apple)

Here are the codes;

Header (MPMoviePlayerViewController_FullscreenFix.h)

#import <MediaPlayer/MediaPlayer.h>

@interface MPMoviePlayerViewController (MPMoviePlayerViewController_FullscreenFix)
- (void)viewDidDisappear:(BOOL)animated;
- (void)viewWillDisappear:(BOOL)animated;
@end

Implementation (MPMoviePlayerViewController_FullscreenFix.m)

#import "MPMoviePlayerViewController_FullscreenFix.h"

@implementation MPMoviePlayerViewController (MPMoviePlayerViewController_FullscreenFix)

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

@end

Now my code is working on both iOS 6.1.3, 5.5.1 and 4.3.5 versions with the exactly same behavior.

Solution 4

I had the same problem, but with loading a video from a url (on the web)

Previously I:

  1. Subscribed for MPMoviePlayerPlaybackDidFinishNotification notifications
  2. Initialized a MPMoviePlayerViewController (no content url at this stage)
  3. Presented it via presentMoviePlayerViewControllerAnimated:
  4. While it was up on screen, I loaded the streamed url (asynchronously)
  5. When the url came back, I would set the content url on the MPMoviePlayerViewController' moviePlayer

As you said, occasionally the MPMoviePlayerViewController would get stuck and wouldn't dismiss itself when the user taps exit, to fix this, I changed my autoplay order, so the flow became:

  1. Subscribed for MPMoviePlayerPlaybackDidFinishNotification notifications
  2. Initialized a MPMoviePlayerViewController (no content url at this stage)
  3. Set the moviePlayer's shouldAutoplay boolean to NO
  4. Presented it via presentMoviePlayerViewControllerAnimated:
  5. While it was up on screen, I loaded the streamed url (asynchronously)
  6. When the url came back, I would set the content url on the MPMoviePlayerViewController' moviePlayer
  7. Set the moviePlayer's shouldAutoplay boolean to YES

Since those two changes, I have yet to see the controller get stuck

Solution 5

The solution is create a property to retain the MPMoviePlayerController class

@property (nonatomic, retain) MPMoviePlayerController *moviePlayerController;

and use the property in your controller

self.moviePlayerController = [[MPMoviePlayerController alloc] init];

[_viewMediaPlayer addSubview:self.moviePlayerController.view];

there is a bug in iOS6 and the MPMoviePlayerController is deallocated when entry in fullscreen mode http://openradar.appspot.com/12327997

Share:
19,835

Related videos on Youtube

snod
Author by

snod

Updated on August 25, 2022

Comments

  • snod
    snod over 1 year

    I have a MPMoviewPlayerViewController embedded into an UIView object. When I start the player in the embedded mode everything works fine and as expected. If the user then taps onto the fullscreen toggle (or if I change to fullscreen programmatically using setFullscreen:animated) the player goes fullscreen, the movie plays for another second and after that the screen goes black with only a "Loading..." message.

    This behavior only appears using iOS 6 (also iPad 6.0 Simulator), on devices running iOS 5 everything works as intended.

    The movie source is a local file from the app bundle.

    Upon playing & entering fullscreen the debug output is as follows:

    2012-09-26 15:24:48.251 [39895:c07] [MPAVController] Autoplay: Disabling autoplay for pause
    2012-09-26 15:24:48.252 [39895:c07] [MPAVController] Autoplay: Disabling autoplay
    2012-09-26 15:24:48.262 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
    2012-09-26 15:24:48.265 [39895:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
    2012-09-26 15:24:48.266 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
    2012-09-26 15:24:48.267 [39895:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
    2012-09-26 15:24:48.268 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
    2012-09-26 15:24:48.276 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
    2012-09-26 15:24:48.286 [39895:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
    2012-09-26 15:24:48.938 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
    2012-09-26 15:24:48.940 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
    2012-09-26 15:24:48.954 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
    2012-09-26 15:24:49.006 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
    2012-09-26 15:24:49.012 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
    

    Has somebody an idea why the player stops working?

    Edit: Added an example project on github

  • snod
    snod over 11 years
    Yes, I already did that. I even tried to send the player to fullscreen first and then start the playback. With the same result.
  • snod
    snod over 11 years
    No, I haven't even implemented those methods. I will try to come up with a minimal sample project which shows the same behavior.
  • snod
    snod over 11 years
    The example project is now linked in the original question.
  • snod
    snod over 11 years
    Because I don't use the movie player as fullscreen from the start but rather embedded with the user having the possibility to switch to fullscreen your solution/way of presenting the vc isn't applicable for me :( Also this doesn't happen occasionally but every time.
  • Mejdi Lassidi
    Mejdi Lassidi over 11 years
    the problem that i used your code in my project and it did not work for me.. the same code i use it in yours downloaded from github it works !!!
  • Mejdi Lassidi
    Mejdi Lassidi over 11 years
    the only difference is the memory management .. i use the famous "retain" not the "strong...weak"
  • Mejdi Lassidi
    Mejdi Lassidi over 11 years
    i find my problem: it was that i made a catch for all exceptions.. so for that my app crash when debuting
  • Dumoko
    Dumoko over 11 years
    Great stuff. Actually the thing that makes it work is not the container view, but the embedded style.
  • bugloaf
    bugloaf over 11 years
    While you @snod may not have implemented these methods, it is calling them on root view controller in the hierarchy and the default implementation is doing some cleanup or something that kills the movie player. Apple may fix this bug, but the cat is out of the bag, and we will have to work around this forever for the people who don't upgrade from 6.0.
  • Harsh Mehrotra
    Harsh Mehrotra over 11 years
    @VikasSRajput "basted"? What does that mean? "Iska matlab kya hai?"
  • Vikas S Singh
    Vikas S Singh over 11 years
    This ans is totally time wasted of time
  • john.k.doe
    john.k.doe over 11 years
    hmmm … i have been using MPMoviePlayerController, and i have been seeing the lockup.
  • Christopher Pickslay
    Christopher Pickslay over 11 years
    Great solution, @Anthony. Thanks!
  • Ashvin A
    Ashvin A over 11 years
    Here what code i have to write for resume my video in this methods: viewWillDisappear: and/or viewDidDisappear:
  • SeanK
    SeanK about 11 years
    This fixed my problem. Thank you very much. I sure hope Apple addresses this.
  • lucasart
    lucasart over 10 years
    This answer should be the approved answer to @snod's question.