Why is the title bar appearing behind the status bar after a rotation? - iphone

I have a UIViewController whose view is a UIWebView with an embedded movie. When the movie is playing full screen, and the device is rotated, the title bar ends up behind the status bar after the movie is dismissed. Why might this happen?

Turns out that the animation of the view controller's view wasn't finished when the video started. This caused it to be redisplayed over the video player view.

My solution:
(void)viewDidLoad
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[UIApplication sharedApplication].keyWindow.frame=CGRectMake(0, 20, 320, 460);
self.navigationController.navigationBar.hidden=NO;
}

did you autoresizingMask on the UIWebView
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth);
and
-(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation
{
return YES;
}

It's no way to resolve this problem using MPMoviePlayerNotification, because UIWebView Video Don't use MPMoviePlayerViewController or it's private for developer.
But, there's another way to fix this bug.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handleStatusBarFrameDidChange)
name:UIApplicationDidChangeStatusBarFrameNotification
object:nil];
- (void)handleStatusBarFrameDidChange {
self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBarHidden = NO;
}

Related

How can I make a video display in Landscape mode on iOS 5?

I'm having a very strange problem. I want a video to appear in landscape mode, but I can't seem to make it work. Even if I can't make it always show Landscape, at least I want it to show ok, and I can't make that either!! Here is my code:
#import "SplashViewController.h"
#import "MainViewController.h"
#import "MediaPlayer/MediaPlayer.h"
#interface SplashViewController ()
#property (nonatomic, retain) NSTimer *timer;
#end
#implementation SplashViewController
#synthesize timer = _timer;
-(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
- (id)init
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self = [self initWithNibName:#"SplashViewController_iPhone" bundle:nil];
} else {
self = [self initWithNibName:#"SplashViewController_iPad" bundle:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSString *url = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"intro.mp4"];
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[playerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];
[self.view addSubview:playerViewController.view];
//play movie
MPMoviePlayerController *player = [playerViewController moviePlayer];
player.scalingMode = MPMovieScalingModeAspectFill;
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[player.view removeFromSuperview];
[self loadMainView];
}
- (void)loadMainView
{
MainViewController *mainVC = [[MainViewController alloc] init];
[self.navigationController pushViewController:mainVC animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
And here comes the weirdness...
If I start the app with my iPad physically in Landscape Mode, the video shows like this (please not that the bar at the top is shorter than the widht! :O)
If I then rotate the iPad to Portrait, it looks like this:
But then, if I start the app with my iPad physically in Portrait Mode, the video shows like this:
And if I then rotate the iPad to Landscape, it looks like this:
Which is GREAT! This final image is what I would like the video to always look like.
Any ideas what I might be doing wrong???
Thanks!
EDIT 1
Ok, with #Tark answer I was able to fix the player display issue. Now it's showing fine no matter how I start the app. Thanks for that!! What is missing now is the always landscape mode.
I tried with the following methods:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
I also tried inserting the row
Initial interface orientation = Landscape (right home button)
In the Info.plist
What I'm getting is that if I start the app in Landscape mode, if I rotate the iPad to Portrait, it stays in Landscape. GREAT!
But if I start the app in Portrait mode, the video shows in Portrait mode. Once I rotate it to Landscape, I can't rotate it back to Portrait, which is good, but I don't want it to start in Portrait!
EDIT 2
Ok, now this is even more weird. If I try it on an iPhone, it works great. No matter if I start the app in Landscape or Portrait, the video is shown always in Landscape.
But if I try it on an iPad, the problem in EDIT 1 arises... :S
Any ideas?
Thanks!
Have you tried setting the frame of the MPMoviePlayerViewControllers view when you add it as a subview?
...
playerViewController.view.frame = self.view.bounds;
[self.view addSubview:playerViewController.view];
...
To make the app only run in landscape mode, you should make sure that you have only selected the orientations you want in the app plist. In Xcode 4 there is a handy Supported Interface Orientations section in the target settings, make sure you only select landscape here. If you still have the issue, you have to make sure that you are disabling autorotation on all visible controllers in the view stack.
shouldAutorotateToInterfaceOrientation is deprecated as of iOS 6, Have you tried using supportedInterfaceOrientations?
If you are trying to support iOS 5 & 6 then I believe you need to use both:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
I haven't tested this so take it for what it's worth.

MPMoviePlayerController rotating in full screen while the parent View Controller only supports portrait orientation

this question is only one part of my problem. I am implementing iOS6 rotation and orientation support for my existing application.
So I have a ViewController that contains a MPMoviePlayerController embedded in ViewController view ( my application requires it ). User can play the video and see it in the embedded view or click on full screen button using the default player controls and player goes to full screen mode.
Now I have restricted the view controller to only support portrait orientation using the new rotation APIs provided by iOS6.
// New Autorotation support.
- (BOOL)shouldAutorotate;
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
this works pretty well. the ViewController only supports portrait and user play the movie in embedded view.
Now the problem comes, when User goes into full screen mode. In full screen mode, the movie is keep on rotating, when i rotate the simulator/device. When i rotate the device while movie being played in full screen mode with breakpoints in shouldAutorotate and supportedInterfaceOrientations , it still comes in these both methods which return NO and UIInterfaceOrientationMaskPortrait respectively, but still the movie is rotating ...
Why is this happening? .... this is one part of my question ... the 2nd part is I want the movie to enter in landscape mode when the user goes to full-screen mode. and I want the movie player to lock in landscape mode until user presses the DONE button.
Please help ....
you can try below function in AppDelegate:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
}
you can make condition here for both mode.
such as if media player is in full screen then
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
otherwise return UIInterfaceOrientationMaskPortrait;
i have not tried it but i think, it should work in your case.
thanks
For clarity, here is the complete code (it ALL goes inside your app delegate):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(willExitFullscreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(willEnterFullscreen:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
}
- (void)willEnterFullscreen:(NSNotification*)notification
{
NSLog(#"willEnterFullscreen");
isFullScreen = YES;
}
- (void)willExitFullscreen:(NSNotification*)notification
{
NSLog(#"willExitFullscreen");
isFullScreen = NO;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (isFullScreen)
return UIInterfaceOrientationMaskLandscapeLeft;
else
return UIInterfaceOrientationMaskPortrait;
}
isFullScreen is a BOOL to be declared in AppDelegate.h
I would suggest to use a MPMoviePlayerViewController instead. Subclass it and implement the supportedInterfaceOrientations method and return UIInterfaceOrientationMaskLandscape.
You might also have to implement the shouldAutorotateToInterfaceOrientation: method.
See the class reference:
MPMoviePlayerViewController
Edit: You might also take a look at this post: iphone - force MPMoviePlayerController to play video in landscape mode
This consumed me for a while and I got so many different horrifying errors, but eventually I ended up not doing it through MPMoviePlayerController but MPMoviePlayerViewController. I just rotated the self.playerView which is a property, before presenting it. Also I added the NSNotification that will lead back to the main control and the main ViewController after the video finishes. Here's how I went about executing it:
[[NSNotificationCenter defaultCenter] removeObserver:self.playerView
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.playerView.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.playerView.moviePlayer];
self.playerView = [[MPMoviePlayerViewController alloc] initWithContentURL:docUrl];
self.playerView.view.frame = CGRectMake(10, 10, self.frame.size.width-20, 180);
[self.playerView.moviePlayer prepareToPlay];
if(IS_IPHONE_6P)
{
[self.playerView.view setBounds:CGRectMake(0, 0, 736, 414)];
[self.playerView.view setCenter:CGPointMake(212, 368)];
}
else if(IS_IPHONE_6)
{
[self.playerView.view setBounds:CGRectMake(0, 0, 375, 667)];
[self.playerView.view setCenter:CGPointMake(187, 333)];
}
else if (IS_IPHONE_5)
{
[self.playerView.view setBounds:CGRectMake(0, 0, 736, 414)];
[self.playerView.view setCenter:CGPointMake(160, 284)];
}
else
{
[self.playerView.view setBounds:CGRectMake(0, 0, 480, 320)];
[self.playerView.view setCenter:CGPointMake(160, 240)];
}
[self.playerView.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
self.playerView.modalPresentationStyle = UIModalPresentationFormSheet;
self.playerView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:self.playerView animated:YES completion:nil];
And the callback movieFinishedCallback: is as follows,
- (void)movieFinishedCallback:(NSNotification*)aNotification
{
// Obtain the reason why the movie playback finished
NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
// Dismiss the view controller ONLY when the reason is not "playback ended"
if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded)
{
MPMoviePlayerController *moviePlayer = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
NSLog(#"Video Closed");
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^
{
[self dismissViewControllerAnimated:NO completion:nil];
self.playerView = nil;
});
}
}
This worked for me. Hope it helps.
in your project, select name project and right window select info tab.
in custom ios target properties
add key and select key: "Initial interface orientation" set value: Portrait (bottom home button)
rebuild your project -> ok
For iOS 6 you can use this answer.
But if you supports < iOS 6 need a different approach.
You must create custom navigation controller and to it add methods for creation with root controller and method for rotation.
It will look like: m file and h file.
And in your AppDelegate must call method for init:
In h file:
#import "IORNavigationController.h"
and
#property (nonatomic, retain) IORNavigationController* navigationController;
In m file:
self.navigationController = [[[MyNavigationController alloc] initWithRootViewController:start] autorelease];
use this
moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI/2);
it work with ios 7
Just add this code to yours view controller
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

MPMoviePlayerController : orientation problem

finally I have to post my problem here. Yes it could be duplicate question here as I have referred many answers regarding to this question.But I could not find any fix. (Also didn't find any question regarding to tab-bar app specific so...) And I don't want to use MPMoviePlayerViewController
I have tab-bar application. In last tab's VC there is a button. On click event I want to start movie player. For that I am using MPMoviePlayerController. Its all fine when orientation is Portrait . But regarding to changes, now I have to play it in landscape mode only.
here is my code :
-(void)playMovie
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
[self.scrollView addSubview:moviePlayer.view];
[moviePlayer play];
[moviePlayer setFullscreen:TRUE];
}
-(void)btnPlayHandler:(id)sender
{
NSLog(#"btnPlayHandler");
NSURL * videoUrl = [NSURL URLWithString:[NSString stringWithFormat:#"%#",[dictResponse valueForKey:#"VideoPath"]]];
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:videoUrl];
//[moviePlayer.view setFrame:CGRectMake(20, 40, 280, 222)];
moviePlayer.fullscreen = YES ;
moviePlayer.shouldAutoplay = NO ;
[self performSelector:#selector(playMovie) withObject:nil afterDelay:1];
}
- (void) movieWillExit:(NSNotification *)notification
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
}
- (void) movieExit:(NSNotification *)notification
{
[moviePlayer stop];
[moviePlayer.view removeFromSuperview];
moviePlayer = nil ;
[btnPlay setHidden:FALSE];
}
- (void)moviePreLoad:(NSNotification *)notification
{
NSLog(#"moviePreLoad");
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(#"moviePlaybackComplete");
[btnPlay setHidden:FALSE];
}
Only device's orientation is changed not player's view ! How to accomplish this ??? Is it because the tab-bar application ?
You are making the window landscape, but as you have set the MPMoviePlayer view in scrollview, it is not rotating. try to rotate the scrollview according to your orientation.
See this link http://blog.sallarp.com/shouldautorotatetointerfaceorientation/. Hopefully it will solve your problem.

MPMoviewPlayerController fullscreen playback rotation with underlying UIViewController with portrait mode only (rotation disallowed)

Hallo,
I have a simple application, which does contain UITabBarController with two UIViewControllers. Both UIViewControllers are portrait only (no rotation allowed). One UIViewController's UIView does contain MPMoviePlayerController's view to allow video playback inside this view with possibility to make it fullscreen via controls (MPMovieControlStyleEmbedded). The code is simple and does look like ...
__moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"MOVIE_URL"]];
__moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
__moviePlayer.view.frame = CGRectMake( 10, 10, 300, 200 );
__moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
__moviePlayer.shouldAutoplay = NO;
[__moviePlayer prepareToPlay];
[self.view addSubview:__moviePlayer.view];
... this does work perfectly unless user switches to fullscreen playback where I want to allow rotation to allow landscape playback too. Rotation doesn't work, because UITabBarController disallows it (and both UIViewControllers too).
So, I tried two approaches, but none of them does work as expected.
1) Subclassed UITabBarController
I did add property BOOL __allowRotation and if it is set to YES, I do return YES in UITabBarController's shouldAutorotateToInterfaceOrientation method.
I'm listening for MPMoviePlayerDidEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification notifications to set this property to YES and NO.
It does work, but the problem is, that when the user ends video playback in landscape, underlying view is not rotated back to portrait. The only way to rotate back to portrait is to use private API, which is no no.
2) View/layer transformation
I also did try to listen for MPMoviePlayerDidEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification notifications.
When I receive MPMoviePlayerDidEnterFullscreenNotification, I'm starting UIDevice orientation notifications to get device orientation. I'm trying to transform MPMoviePlayerController's view layer based on current device orientation, but it's kinda immune, because it does nothing. I can assign whatever to transform property, but it does nothing.
It does nothing is not quite correct. When I apply transformation during rotation, I can see effect of this transformation when I switch back from fullscreen to embedded video playback.
3) Separate UIWindow
I did not test this yet, but I've found somewhere that MPMoviePlayerController creates separate UIWindow for fullscreen playback, which should be accessible via [[UIApplication sharedApplication] windows]. This does explain why transformation is not applied during fullscreen playback.
But I quite dislike this solution, because the UIWindow can't be identified and I do not want to use magic constants like objectAtIndex:1 or apply transformation to all UIWindows except the main one, etc.
Beside the fact that the underlying implementation can be modified and it will stop working.
Question
So, the question is, how to allow MPMoviePlayerController fullscreen playback only rotation when underlying UIView (ie. UIView's UIViewController) prohibits rotation and allows portrait only?
I have a very similar situation. My app is portrait-only. But I need to show full-screen videos in any orientation, and then get back to the portrait orientation, after the user quits full-screen mode.
Split's method doesn't work for me, because I would like to let user watch the video in fullscreen and embedded, and switch between modes, not loosing the play position, and without any pauses.
I found this workaround:
First, I have a root UINavigationController subclass, that receives all messages regarding rotation.
I forbid the rotation in this controller with:
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation {
return (UIInterfaceOrientationPortrait == toInterfaceOrientation);
}
I am overriding the
- (id) initWithRootViewController:(UIViewController *)rootViewController; method.
Adding the support for device orientation modifications:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(receivedRotate:) name: UIDeviceOrientationDidChangeNotification object: nil];
Now I have a handler receivedRotate: - that catches all the device rotations in spite of not auto-rotating to any orientations except portrait:
- (void) receivedRotate:(NSNotification*) notify {
if(isVideoFullscreen) {
UIDeviceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:2];
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
self.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
self.view.bounds = CGRectMake(0, 0, 1024, 768);
} else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
self.view.bounds = CGRectMake(0, 0, 1024, 768);
} else if(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
self.view.transform = CGAffineTransformMakeRotation(M_PI);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown];
self.view.bounds = CGRectMake(0, 0, 768, 1024);
} else if(toInterfaceOrientation == UIInterfaceOrientationPortrait) {
self.view.transform = CGAffineTransformMakeRotation(0);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
self.view.bounds = CGRectMake(0, 0, 768, 1024);
}
[UIView commitAnimations];
}
}
I just check the rotations of the device, and rotate my view accordingly.
Then - how do the root controller knows, when the video is fullscreen?
Just add two other message handlers to the init:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
And the handlers themselves:
- (void) willEnterFullscreen: (NSNotification *) notify {
isVideoFullscreen = YES;
}
- (void) willExitFullscreen: (NSNotification *) notify {
self.view.transform = CGAffineTransformMakeRotation(0);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
self.view.bounds = CGRectMake(0, 0, 768, 1024);
isVideoFullscreen = NO;
}
When exiting fullscreen - we restore the portrait orientation.
So, this works for me, hope it will help someone.
You can try to present new UIViewController (with shouldAutorotate YES) modally and add __moviePlayer.view into this controller when it sends MPMoviePlayerWillEnterFullscreenNotification. Do the opposite when moviePlayer exits fullscreen.
Register for MPMoviePlayerWillExitFullscreenNotification and MPMoviePlayerWillEnterFullscreenNotification in app delegate and handle the orientation using an instance variable.
-(void)moviePlayerFullScreen:(NSNotification *)notification
{
if ([notification.name isEqualToString:#"MPMoviePlayerWillEnterFullscreenNotification"]) {
self.supportedOrientation=UIInterfaceOrientationMaskAll;
}
else if ([notification.name isEqualToString:#"MPMoviePlayerWillExitFullscreenNotification"])
{
self.supportedOrientation=UIInterfaceOrientationMaskPortrait;
}
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return self.supportedOrientation;
}
The MPMoviePlayerViewController has its own function to present videos modally:
NSURL *videoURL = [NSURL fileURLWithPath:video.path];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
//Calls for movie playback once video is finished
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
playerView = [[MPMoviePlayerViewController alloc]init];
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[playerView setView:moviePlayer.view];
[moviePlayer.view setFrame: self.view.bounds];
[self presentMoviePlayerViewControllerAnimated:playerView];
[moviePlayer play];
NSLog(#"playing video view");
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.....

Delay between play button and movie showing

I have a simple view that creates a MPMoviePlayerViewController when the user presses a button, using the presentMoviePlayerViewControllerAnimated: method. The new view controller slides in and shows the movie player, so far so good.
However, when the button is pushed, the current view controller slides out the bottom, showing a ugly (probably default) white view, that sticks around anywhere from half a second to a few seconds, until the movie view controller is shown. It seems like it's dependent on my network connection, as if the movie view controller is downloading parts of the movie before showing the player.
Am I doing something wrong, or how can I work around this? I'd really prefer to just show the movie view controller directly, maybe even without sliding out the previous view controller that holds the play button, but still animated like a modal view controller.
Thanks!
Christoph
The solution was to init the player view controller when the parent view is created, and then call prepareToPlay on the moviePlayer inside it. That removes the latency when the play button is pushed and (I guess) moves it to when the user gets to the parent view from which he can play the movie.
EDIT:
This removes the delay, but for some reason, initializing the movie view controller also autoplays it when it's loaded, so that's not a good solution.
I ended up just setting the background of the view to black. Doesn't fix the delay, but makes it look much nicer:
theMovieVC.view.backgroundColor = [UIColor blackColor];
this is what i do for iOS > 3.2 :
- (void) play {
mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mMovieURL];
if ([mMoviePlayer respondsToSelector:#selector(loadState)])
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePreloadDidFinishIOS32:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
[mMoviePlayer prepareToPlay];
[mMoviePlayer play];
mMoviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[mMoviePlayer setMovieControlMode:MPMovieControlModeDefault];
[mMoviePlayer setBackgroundColor:[UIColor clearColor]];
}
}
and
- (void) moviePreloadDidFinishIOS32:(NSNotification*)notification;
{
// Remove observer
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
self.view = mMoviePlayer.view;
}
Thus in the viewdidload you can instantiate what you want (UIActivityIndicatorView for example). The view controller will only be replaced when the preload is finished.
I'm noticing the same issue in my app. Anyone have suggestions to avoid this issue?
In my case, I'm pushing the MPMoviePlayerViewController to the UI as a modal popup.
// build the movie player
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
MPMoviePlayerViewController *movieViewController = [[[MPMoviePlayerViewController alloc] initWithContentURL:request.URL] autorelease];
[movieViewController.moviePlayer prepareToPlay];
movieViewController.view.backgroundColor = [UIColor blackColor];
// show the movie player view
[self.parentViewController presentModalViewController:movieViewController animated:YES];