MPMoviePlayerController breaks/stops after going to fullscreen in iOS6
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:
- Subscribed for
MPMoviePlayerPlaybackDidFinishNotification
notifications - Initialized a
MPMoviePlayerViewController
(no content url at this stage) - Presented it via
presentMoviePlayerViewControllerAnimated
: - While it was up on screen, I loaded the streamed url (asynchronously)
- 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:
- Subscribed for
MPMoviePlayerPlaybackDidFinishNotification
notifications - Initialized a
MPMoviePlayerViewController
(no content url at this stage) - Set the moviePlayer's
shouldAutoplay
boolean to NO - Presented it via
presentMoviePlayerViewControllerAnimated
: - While it was up on screen, I loaded the streamed url (asynchronously)
- When the url came back, I would set the content url on the
MPMoviePlayerViewController
' moviePlayer - 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
Related videos on Youtube
snod
Updated on August 25, 2022Comments
-
snod over 1 year
I have a
MPMoviewPlayerViewController
embedded into anUIView
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 usingsetFullscreen: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 over 11 yearsYes, I already did that. I even tried to send the player to fullscreen first and then start the playback. With the same result.
-
snod over 11 yearsNo, I haven't even implemented those methods. I will try to come up with a minimal sample project which shows the same behavior.
-
snod over 11 yearsThe example project is now linked in the original question.
-
snod over 11 yearsBecause 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 over 11 yearsthe 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 over 11 yearsthe only difference is the memory management .. i use the famous "retain" not the "strong...weak"
-
Mejdi Lassidi over 11 yearsi find my problem: it was that i made a catch for all exceptions.. so for that my app crash when debuting
-
Dumoko over 11 yearsGreat stuff. Actually the thing that makes it work is not the container view, but the embedded style.
-
bugloaf over 11 yearsWhile 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 over 11 years@VikasSRajput "basted"? What does that mean? "Iska matlab kya hai?"
-
Vikas S Singh over 11 yearsThis ans is totally time wasted of time
-
john.k.doe over 11 yearshmmm … i have been using MPMoviePlayerController, and i have been seeing the lockup.
-
Christopher Pickslay over 11 yearsGreat solution, @Anthony. Thanks!
-
Ashvin A over 11 yearsHere what code i have to write for resume my video in this methods: viewWillDisappear: and/or viewDidDisappear:
-
SeanK about 11 yearsThis fixed my problem. Thank you very much. I sure hope Apple addresses this.
-
lucasart over 10 yearsThis answer should be the approved answer to @snod's question.