Forcing landscape orientation on fullscreen MPMoviePlayerController prevents correct rotation when exiting fullscreen
Hi all I had same problem I resolved it -
Here is my complete code....
You need to first change in appdelegate:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[[NowPlaying sharedManager] playerViewController] allowRotation])//Place your condition here
{
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
Register Notifications for the full screen control:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
Then add line of code in the player controller:
- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification *)notification
{
dispatch_async(dispatch_get_main_queue(), ^
{
self.allowRotation = YES;
});
}
- (void)moviePlayerWillExitFullscreenNotification:(NSNotification *)notification
{
self.allowRotation = NO;
[self.moviePlayerController setControlStyle:MPMovieControlStyleNone];
dispatch_async(dispatch_get_main_queue(), ^
{
//Managing GUI in pause condition
if (self.currentContent.contentType == TypeVideo && self.moviePlayerController.playbackState == MPMoviePlaybackStatePaused)
{
[self.moviePlayerController pause];
if (self.playButton.selected)
self.playButton.selected = NO;
}
self.view.transform = CGAffineTransformMakeRotation(0);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
self.view.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
});
}
This code is tested in iOS6 and iOS7 working fine. Thanks :)
Please let me know if there is any question.....
Prevent MPMoviePlayerController rotating and scaling to portrait when in fullscreen
This seems to be rather difficult if you really want to avoid using MPMoviePlayerViewController.
One option, that seems to work even if you have it in fullscreen, is to manually set the frame of the MPMoviePlayerController's view.
(Note that in other iOS issues, sometimes using the background view has produced different results, but it's worth a shot).
MyMPMoviePlayerController.view.frame = CGRectMake(0, 0, your numbers, here);
However, Apple, in their docs, says that the controller's frame should be set to the frame of it's parent view.
[MyMPMoviePlayerController.view setFrame: parentView.bounds];
The less elegant solution, but one that might work even if that one doesn't is this:
Listen for the UIDeviceOrientationDidChangeNotification and take the movie player's view. Apply a transfrom, bounds, and center (or frame, etc) on it so that it still fits in the landscape view. Essentially transform it back each time it tries to rotate away. (This is all assuming that you really cannot keep it from rotating with shouldAutorotateToInterfaceOrientation:).
The only issue here is that it may keep the movie in portrait but screw around with the view, which is not the desired outcome.
MPMoviePlayerController leaves App in incorrect orientation after fullscreen mode
So why are my views rotated to portrait even when all shouldAutorotateToInterfaceOrientation tell iOS to not rotate to portrait? And how can I make sure the movieplayer does not rotate my views?
If your solution also locks the movieplayer itself in landscape, that's fine with me. As long as my views aren't rotated it's fine with me! :)
I had this exact problem when using this view hierarchy :
+------------------------+ +-------------------+
| | | |
| UINavigationController +->| Some Intermediate |
| | | View Controllers |
+------------------------+ | |
+---------------+---+
|
v
+--------------------------+
| MPMoviePlayerController |
| (embed) |
+--------------------------+
All of the Intermediate view controllers were locked to Landscape orientation so the App could never be in Portrait, except if the MPMoviePlayerController was in full screen (leading to the exact same problem as the OP).
The solution was to lock the UINavigationController to Landscape orientation by creating a subclass that overrides shouldAutorotateToInterfaceOrientation
. This way the MPMoviePlayerController no longer rotates to Portrait orientation. I suspect when entering fullscreen it adds itself to the rootViewController of the mainWindow, which in my case is the UINavigationController (or rather my subclass).
Hope this helps!
MPMoviePlayerController fullscreen in landscape mode in a portrait project
You have 2 options:
- Enable landscape mode in the project settings and override
supportedInterfaceOrientations
for your view controllers. - In your app delegate, add the
application:supportedInterfaceOrientationsForWindow:
method and, when playing a movie, make sure that this returnsUIInterfaceOrientationMaskAllButUpsideDown
.
MPMoviePlayerController does not change Orientation in full-Screen mode in iOS 5
My sandbox app:
https://github.com/comonitos/programatical_device_orientation
The solution is easy:
in interface (h file) :
BOOL rotated;
in implementation (m file):
1. rewrite
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return rotated;
}
2 call [self setup]
-(void) setup {
rotated = YES;
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
rotated = NO;
}
MPMoviePlayerController can rotate in full screen while the Application only supports portrait orientation in ios 7
Finally, i resolve the problem. i have not mentioned that i have been used 3rd party library which is "viewdeck II". And it brokes rotation cycle.
My advise who faced this kind problem, checking your 3rd party libraries...
MPMoviePlayerController done button, Landscape orientation
The culprit of this whole mess was this line of code
[self.mpPlayer setControlStyle:MPMovieControlStyleFullscreen];
So it seems that setting Fullscreen control style when going into fullscreen mode will break done button....
Makes no sense to me. But when I commented out this line I am able to recive willExitFullscreen notification and I can work with that.
Related Topics
How to Group Array of Objects by Date in Swift
iOS Client Certificates and Mobile Device Management
Using Sysctlbyname() from Swift
Visually Modifying a Uitoolbar from Xcode Storyboard
Thread 1:Exc_Bad_Access (Code = 1, Address = 0X30000008)
Firebase Pod Install - Pod 'Firebase/Database' - Required a Higher Minimum Deployment Target
iOS 10 - App Crashes to Access Photo Library or Device Camera via Uiimagepickercontroller
<Googlemaps/Googlemaps.H> File Not Found Google Maps Sdk for iOS
Error Setting Text in Collection View Cell
Can an iOS App Switch the Device to Silent Mode
How to Make a Mkannotationview Touch Sensitive
Core Bluetooth State Preservation and Restoration Not Working, Can't Relaunch App into Background
Document Directory Path Change When Rebuild Application
Why Isn't Preferredcontentsize Used by iPhone 6 Plus Landscape
Authentication with Wkwebview in Swift
How to Crop a Uiimage in Swift
How to Get Vcf Data with Contact Images Using Cncontactvcardserialization Datawithcontacts: Method