MPMediaPickerController orientation on iPad

£可爱£侵袭症+ 提交于 2019-12-05 05:59:32

Not sure whether you are interested in the solution or not, since you asked this in 2010. Anyway, after a few searches here is what I found:

  1. MPMediaPickerController DOES NOT SUPPORT LANDSCAPE ORIENTATION.

  2. In order to make the MPMediaPicker appear nicely in landscape orientation, we can make use of PopOverController. Basically, we create a pop over, and insert the picker into it. PopOverController, when displayed properly from the rootViewController, will indeed follow the orientation of the device.

Here is the rough code. It works, but needs some cleaning up. Probably best you check whether the popover is nil or not, otherwise it will just stack up on itself each time the user tap on the 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 tied to a Toolbar Bar button.

I'm simply pushing it onto 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];

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

here is some sample code you can try it one , after rotation you have to set media palyer view in center of self.view, here some sample code... you have to add MediaPlayer Framework at 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 portrait we have to set frame according to portrait frame like..

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

after that we have to set to center of view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!