MPMoviePlayerViewController Not Rotating until app restart - iphone

K here is an interesting problem
We have an app that is presenting with unusual behavior
If you install that app (from either test flight or via xcode debug) onto a "clean" device (where the app has not existed before or has been previously delete) when the app plays a mp4 from the web or from local memory. The MPMoviePlayerViewController used to play the app will not rotate.
However if you force quit the app and start it again, everything rotates correctly. Even if you quit and return without closing the background thread the video will not rotate.
Here is the simple code
mediaController = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL fileURLWithPath: videoPath]];
[self presentMoviePlayerViewControllerAnimated: mediaController];
[mediaController release];
Any Ideas?

It might be that one of the root view for another one of the tabs is stopping the root view containing your player from rotating. The UITabBarController asks all its children view controllers (one for each tab) whether it should allow rotation and will only allow one to rotate to a given orientation if all of them allow it. This is done so as to avoid the orientation switching violently from one to another when the user switches tabs. Try putting a breakpoint in the shouldAllowAutoRotation for all of the UITabBarController's children and see if they get called.

I discovered the issue with this. the UIWindow can only have one view. If another is added, 2nd views will not receive the notification. I had an action that was triggering on the first load that was doing this causing the views to not rotate.

Related

Unbalanced calls to begin/end appearance transitions for <GKModalRootViewController: 0xb7e450>

I give up on that point, I just can't figure out what is wrong and where...
Here is the problem: in my iPhone application using Cocos2d, I configured autorotation through a viewController; however, since, when Game center opens its view as the user taps on "Create new account" during the authentication, this view does not receive any touch, but the touch go to the game's view (which is hidden under the Game center view).
I have tried everything I thought about, but since I did not find any callback about this Game Center View, it is hard to find a way to correct this...
Here is the initialization of the game's view:
// Init the UI View Controller
//
viewController = [[SQViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
EAGLView *view = [EAGLView viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGBA8 depthFormat:GL_DEPTH_COMPONENT24_OES];
[director setOpenGLView:view];
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[view removeFromSuperview];
[viewController setView:view];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
I have tried many other things, commented every single line in this code, tried some others (such as setHidden:NO, bringSubviewToFront...), but the only results I could get were:
- Game display ok, Game Center ok, but no autorotate
- Game displayed in portrait (the view controller only allow landscape modes), Game Center ok, no autorotate
- Game not displayed (black screen), Game Center ok
And no way to make it all work together... The only clue I have is the title of this topic, "Unbalanced calls to begin/end appearance transitions for ." But since I do not call the Game Center view myself, I don't know what to do with this...
Anyone, any idea?
I've had the same problem while displaying game center leaderboards in my cocos2d built App ever since moving up to iOS 5.0. I've seen references elsewhere to this being caused by a sub viewcontroller losing focus on the parent viewcontroller, but I've been unable to verify that or get this resolved in my app either.
Good news is that I've run this thru instruments - No Memory Leaks. Also executed the same action repetitively with no apparent failures or ill effects.
So while this message is an annoyance, it doesn't appear (at least for now) to adversely affect the App.
This Error occurs when you try to push a viewController before previous ViewController is finished . Means you are trying to push 2 ViewControllers at the same time.

Unable to add overlay to MPMoviePlayerController in SDK 4.1

This is a follow-on from: Overlay on top of Streaming MPMoviePlayerController
I've seen the various threads about checking for a new Window and then using that to apply my custom views to my fullscreen video however in SDK 4.1 this doesnt appear to be the case.
I have tried a timer and listening for UIWindowDidBecomeKeyNotification but in neither case does [[UIApplication sharedApplication] windows] ever contain more than 1 item.
I have tried adding my view to the players view property which works fine when displayed in place, but not when fullscreen, even if I add it in moviePlayBackDidEnterFullScreen event
I found a solution to this problem a few weeks ago:
It seems this method does not work on the iPad (I havent checked iPhone SDK 4>) so in order to get round it you can do the following.
After adding your video and setting to fullscreen you can add your controls directly to the UIWindow (e.g. [[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubView:myView]), they will then appear on top of your video video.
The only problem I have found with this is that they don't obey the orientation rules of the view and I have manually had to program the rotation code in the willRotateToInterfaceOrientation method of the view.

Setting MPMoviePlayer controlStyle to MPMovieControlStyleNone crashes app

I have an app which uses a manager to offer up the relevant custom view for a selected item when selected.
The selection is done through one of 3 parent custom views
TableView
PageControl
Gallery (essentially another TableView)
One of the custom views displays a view with an embedded MPMovieControl on it.
This works fine however for some reason in the Gallery view if I have set the controlStyle of the video set to MPControlStyleNone the app crashes, well it locks up the simulator and Xcodes debugger doesnt even notice, just assumes its still running.
This line is the culprit
player.controlStyle = MPMovieControlStyleNone;
Without it, it works fine, but then I obviously have the unrequired controls displayed
iOS 2.0 through iOS 3.1 uses movieControlMode. Everything newer uses controlStyle. Test for newer and fall back to older.
if ([movie respondsToSelector:#selector(setControlStyle:)]) {
movie.controlStyle = MPMovieControlStyleNone;
} else {
movie.movieControlMode = MPMovieControlModeHidden;
}
May be this will work.
[player setControlStyle:MPMovieControlStyleNone];
Run the program using the profiler and check for NSZombies. Most likely the app is crashing due to a wrong release count or an autorelease and the symptom is your movie crashing when it might be something related to you starting the movie and needing it later to find it was released.

iPad rotation bug when using MPMoviePlayerViewController

Issue summary
Changing the orientation of an iPad device or simulator while playing a video using MPMoviePlayerViewController results in an inconsistent rotation state upon dismissal of the video player. This is a known bug in iPad SDK 3.2, documented at http://www.openradar.me/8012810
Sample project
I have prepared a minimal sample project using the View-based Application template from Xcode 3.2.2, using the following code to launch the player
NSURL *movieUrl = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[self presentMoviePlayerViewControllerAnimated:player];
[player release];
The code is available on GitHub at http://github.com/adamalex/FullScreenMovie or direct download using http://github.com/adamalex/FullScreenMovie/zipball/master
Steps to reproduce
Obtain the project using the information above
Launch the project with the iPad simulator or device
Tap the button to begin playing the video
Rotate the iPad by 90 degrees
Dismiss the video
Note the UIStatusBar is out of sync with the application UI
Objective
I have contacted Apple and they have confirmed this is a bug that is being investigated. I would like to discuss temporary workarounds that use public APIs safe for submission to the App Store. I am going to open a developer support case with Apple as well and will report back with my own progress.
Successful response from Apple Developer Technical Support!
This is a known bug and a we're received a number of duplicate bug reports and so iOS engineering is aware of the issue and we do have a temporary workaround as suggested by iOS engineering.
You will need to implement this in the view controller which presents the movie player.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[self performSelector:#selector(fixStatusBar) withObject:nil afterDelay:0];
}
- (void)fixStatusBar {
[[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] animated:NO];
}
While this is somewhat ugly, it should fix the issue for now. It would be recommended to remove this code once the bug is fixed in the system.
This took care of the issue completely for me, and you can revisit http://github.com/adamalex/FullScreenMovie for the code with the fix applied.
This also solves an iPhone/iPodTouch rotation issue that I was struggling with. I am developing a universal app in which each view displays a different image depending on whether the device is in portrait or landscape orientation. Buttons are used to navigate between views.
If the app is running on the device and a portrait view is rotated to landscape, my image switching takes place. If the device is then placed flat on a table top and the button is tapped to display the next view, the view appears in landscape but shows the portrait image instead. I solved the problem by forcing a portrait view to appear by detecting for face up and down, but Apple's code solved this problem (as well as the similar movie problem I was also experiencing).
Many thanks for reporting the bug - I assumed it was just my bad coding...

MPMoviePlayer Audio Album art

I am streaming an MP3 file using MPMoviePlayer, and I would like to have an image displayed instead of the default Quicktime logo in the background.
I found out a way to have an image overlay the player, but the problem with that, is you have to tap outside the image to get the player controls to appear. And when they do appear, they are underneath the image.
Does someone know how to do this?
Thanks,
John
backgroundColor is deprecated, and diving into private View structures is dangerous. This worked fine for me:
UIImageView *coverImageView = [[UIImageView alloc] initWithImage:coverImage];
coverImageView.contentMode = UIViewContentModeScaleAspectFit;
coverImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
coverImageView.frame = moviePlayerController.view.bounds;
[moviePlayerController.view addSubview:coverImageView];
Most every app on the iPhone is made of a hierarchy of views. You could go up to the top root node of the movie player and walk down the child views recursively and set the hidden value to YES until you find the right item, then insert your UIImageView below that item. That way, the controls stay on top and still respond to user inputs.
The risk you run is if Apple changes the MPMoviePlayer UI and shuffles the view hierarchy, but you'll probably have lots of advance notice and can patch your app to allow for the new layout.
There is a question as to whether this is kosher for appstore apps, but many current apps (especially camera/picture-taking ones) are doing it to get rid of standard window elements.
Use AVAudioPlayer and implement your own player UI.
it will work check this
MPMoviePlayerController *moviePlayerController=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
moviePlayerController.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Default.png"]];