Orientation MPMediaPickerController on iPad

How to set the correct orientation of MPMediaPickerController?

I return YES to shouldAutorotateToInterfaceOrientation, but I have a bad frame for Landscape (if you first show MPMediaPickerController in Portrait, and vice versa).

I rotate my device randomly, and once a frame to fix myself! I found a way to set the frame by rotation - you need to rotate it 180 degrees. For example, if you have a good frame in Portrait, when you rotate in Landscape - you have a bad frame (from Portatait), but if you rotate in another landscape (up to 180 degrees), then the frame is set to Landscape ... Why?

How can I set the frame after the correct rotation?

Yours faithfully,

+6
iphone ipod
source share
3 answers

Not sure if you are interested in a solution or not, since you asked for it in 2010. Anyway, after a few searches here I found:

  • MPMediaPickerController DOES NOT SUPPORT LANDSCAPE ORIENTATION.

  • To make MPMediaPicker look beautiful in landscape orientation, we can use PopOverController. Basically, we create a popup and paste the collector into it. PopOverController, if displayed correctly from the root controller, will really follow the device orientation.

Here is a sample code. It works, but requires some cleaning. It is probably best to check if popover nil is really or not, otherwise it will simply add up to itself every time the user clicks a button.

- (IBAction)showMediaPicker:(id)sender { MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny]; mediaPicker.delegate = self; mediaPicker.allowsPickingMultipleItems = YES; mediaPicker.prompt = @"Select musics..."; UIPopoverController *colorPickerPopover = [[[UIPopoverController alloc] initWithContentViewController:mediaPicker] retain]; [colorPickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } 

A little more note: this IBAction is bound to a toolbar button.

+2
source share

I just click it on my navigation controller:

 MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny]; mediaPicker.delegate = self; mediaPicker.allowsPickingMultipleItems = NO; mediaPicker.prompt = @"Select songs..."; [[self navigationController] pushViewController:mediaPicker animated:YES]; 

Of course, this only works in the context of the navigation controller, but it works and is simple!

0
source share

here is a sample code, you can try it alone, after rotation you need to set the palyer multimedia view in the center of self.view, here is a sample code ... you need to add MediaPlayer Framework first ....

 NSString* moviePath = [[NSBundle mainBundle] pathForResource:@"PATRON_LOGO_3" ofType:@"mp4"]; NSURL* movieURL = [NSURL fileURLWithPath:moviePath]; MPMoviePlayerController *playerCtrl = [[MPMoviePlayerController alloc]initWithContentURL:movieURL]; playerCtrl.scalingMode = MPMovieScalingModeFill; playerCtrl.controlStyle = MPMovieControlStyleNone; [playerCtrl.view setCenter:CGPointMake(240, 160)]; [playerCtrl.view setTransform:CGAffineTransformMakeRotation(M_PI/2)]; playerCtrl.view.frame = CGRectMake(0, 0, 320, 480); [self.view addSubview:playerCtrl.view]; [playerCtrl play]; 

I think it works fine, this is for landscape mode for portraiture, we need to set the frame to fit the portrait, for example ..

playerCtrl.view.frame = CGRectMake (0, 0, 480, 320);

after that we have to set the center of the review.

-one
source share

All Articles