I have an iPhone application (iOS6+) that supports all interface orientations. However, only landscape orientation should be supported when an MPMoviePlayerController is playing a video fullscreen.
I found the following solution on Stack Overflow and it works.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
...
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.landscapeOnlyOrientation) {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskAll;
}
- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = YES;
}
- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = NO;
}
However, an annoying problem persists, namely that if the video exits fullscreen in portrait orientation (after playing in forced landscape), the underlying view doesn't rotate back. I have to manually rotate the device to landscape and back to portrait to trigger updating of the orientation. Is there some way I can trigger this kind of update programatically?
The following set of screenshots should illustrate what I mean:
NB: For various reasons, using MPMoviePlayerViewController is not possible.
You need to subclass and provide landscape as supported interface orientation.
you need to add this code for iOS7 it works perfect and simple
Hi all I had same problem I resolved it -
Here is my complete code....
You need to first change in appdelegate:
Register Notifications for the full screen control:
Then add line of code in the player controller:
This code is tested in iOS6 and iOS7 working fine. Thanks :)
Please let me know if there is any question.....
I think you can register your viewcontroller for device orientation and call viewcontroller's orientation method forcefully.
You could try to "force" an orientation refresh to let the system handle the correct orientation for you:
It's hack-ish but it works.
You use supportedIterfaceOrientationsForWindow then look for: MPInlineVideoFullscreenViewController. It is a bit tricky to find right view controller but it works.
Here is the sample code: