MPMediaPickerController orientation on iPad - iphone

How can I set correct orientation of MPMediaPickerController ?
I've return YES in shouldAutorotateToInterfaceOrientation, but i have bad frame for Landscape (if show MPMediaPickerController in Portrait first, and conversely).
I've rotating my device chaotically and sometime frame set to correct himself!
I've find the method to set frame by rotating - need rotate to 180 degreess.
For example, if you have good frame in Portrait, when you rotate to Landscape - you have bad frame (from Portatait), but if you rotate to other landscape (to 180 degreess), then frame set to Landscape...
Why ?
How can i set the frame after rotation correct always ?
regards,

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:
MPMediaPickerController DOES NOT SUPPORT LANDSCAPE ORIENTATION.
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.

Related

GameCenter Orientation Problems

I got a lot of problems implementing Game Center.
My game its based on Cocos2d But my Menu I do it with XIB. So the main window i make it like this:
UIWindow
UINavigationController
Navigation Bar
UIViewController [Menu]
UINavigationItem
When i click on Play I create a new View Controller called Menu2Game.h.m.xib And i add the OpenGL to this view, and then Menu2Game add it to my menu View
menu2Game = [[Menu2Game alloc] initWithNibName:#"Menu2Game" bundle:nil];
[menu2Game setView:glView];
[self.view addSubview: menu2Game.view];
I don't know why I can't add it directly... But when I click on leaderboards I do the same thing. Presenting the view directly on Menu doesn't work.
UIViewController *tempView = [[UIViewController alloc] init];
[self.view addSubview:tempView.view];
[[GameCenter sharedGameCenter] showLeaderboard:tempView];
And when I call my leaderbords its this code.
if ([self isGameCenterAvailable]) {
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil) {
screen = screen2;
leaderboardController.leaderboardDelegate = self;
[screen presentModalViewController: leaderboardController animated: YES];
[leaderboardController setCategory:#"015.1"];leaderboardController.view.frame.origin.y);
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);
}
}
The problem here its that doesn't respects the application Orientation
If its in Landscape. It start in 80, 320, And finish in 480, 320
It appears and you can use it but appears not in ----> this direction it moves like with 45 degrees
And if you hold the phone in Portrait [Any]. It appears only a small fragment of the leader boards, Facing the real orientation, but the coordinated are different it takes the ones you are holding. And in my plist its not permuted portrait.
How could i fix this? I got 1 week to finish this game and this is the only thing I miss.
Thanks to everybody
I don't know why but just create should rotate and return true.., and eliminate all the code that modify the game center
this one:
[leaderboardController setCategory:#"015.1"];leaderboardController.view.frame.origin.y);
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);
}

Rotate the screen manually to Landscape and there is a white bar left behind on left of screen where the old status bar was placed

I have one screen in my app that I need in portrait as I use a video camera on this screen.
So I load my view then call this method:
- (void)rotate
{
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +80.0);
[self.tabBarController.view setTransform:landscapeTransform];
self.tabBarController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
self.tabBarController.view.center = CGPointMake (240.0, 160.0);
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
There is a 20 pixel wide white area along left hand side of the screen, where the status bar used to be drawn while the screen was in portrait mode.
Same problem exists when I replace the self.tabBarController.view in the above code with self.view
Maybe there is someway to target the very root view of the app if self.view is not that view.
The xib for this view is 480 pixels in size. Can anybody give me some advise as how to fix this problem?
When I take this view out and make appear in a an app without any navbar and placed directly on the main view it transforms ok without the white space on the left.
Many Thanks,
-Code
You should trust rotation to ios default orientation changes.
In order to programmatically rotate to desired orientation:
//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];
//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
Hopefully it will help!
P.S.Tested on sdk 3.2.5 ios 5.0.1.

iphone: displaying small, live camera image in window (2)

I am having a great deal of trouble displaying at small, live camera image in a viewController.
I would have expected the following code to show camera display to appear in a 100x 100 window, but it keeps appearing full screen!
Help appreciated.
camera = [[UIImagePickerController alloc] init];
UIView *cameraHUD = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
cameraHUD.userInteractionEnabled = YES;
[camera setSourceType:UIImagePickerControllerSourceTypeCamera];
camera.showsCameraControls = NO;
camera.navigationBarHidden = YES;
camera.toolbarHidden = YES;
camera.cameraOverlayView = cameraHUD;
[self presentModalViewController:camera animated:YES];
[self.view bringSubviewToFront:cameraHUD];
You are present a new view instead of your actual view, so by default a new UIView has contentmode= scale to fill.
You have to add for example something like:
[camera setContentMode:UIViewContentModeTopLeft];
But if you want do something cool you have to add your Camera View as subview.
I hope it can help you
bye ;)

iPhone SDK - How to disable the volume indicator view if the hardware buttons are pressed?

Is there a way to prevent the volume indicator view form showing if you press the volume up/down hardware buttons?
It's needed for a demo app only. So the method don't need to be App Store safe.
It works like that:
play a silent file
add a volume View to your main view
send the view to back
e.g
NSString *url = [[NSBundle mainBundle]
pathForResource:#"silent" ofType:#"mp3"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:
CGRectMake(0, 0, 1, 1)] autorelease];
[self.view addSubview:volumeView];
[self.view sendSubviewToBack:volumeView];
IIRC, the presence of a MPVolumeView inhibits the display of the volume indicator overlay. Try sticking it the relevant view and seeing if this is the case.
Then you can try various tricks to make it effectively invisible:
Make it hidden (or make a superview hidden).
Set its alpha (or the alpha of a superview) to 0, or 0.01, or so.
Move it off-screen
Move it almost off-screen (e.g. so only the top-left pixel is on screen)
Stick it under another view.
Stick it in a subview with clipsToBounds=ON, and move it outside those bounds
Set volumeView.layer.mask to a new (thus fully-transparent) CALayer. Set volumeView.userInteractionEnabled = NO.
All of these are theoretically detectable by MPVolumeView, but I suspect some of them will work.
- (void)viewDidLoad
{
[super viewDidLoad];
//get current volume level
oldVolume= [[MPMusicPlayerController applicationMusicPlayer] volume];
//hide volume indicator
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:
CGRectMake(0, 0, 1, 1)] autorelease];
musicController=[MPMusicPlayerController applicationMusicPlayer];
[self.view addSubview:volumeView];
[self.view sendSubviewToBack:volumeView];
[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:#selector(volume) userInfo:nil repeats:YES];
}
- (void)volume
{
if ([musicController volume]>oldVolume || [musicController volume]<oldVolume) {
[musicController setVolume:oldVolume];
// do some stuff here and the volume level never changes, just like volume action in camera app
}
}

Adjust size of MPMediaPickerController's view?

In my application I don't use the upper bar that displays Wi-Fi/Date/Time because it's a game. However I need to be able to let my user to pick his music, so I'm using a MPMediaPickerController. The problem is, that when I present my controller, the controller ends up leaving a 10 pixels ( aprox ) bar at the top of the screen, just in the place the Wi-Fi/Date/Time bar, should be present.
Is there a way I could make my MPMediaPickerController bigger ? or to be presented upper in the screen ?
// Configures and displays the media item picker.
- (void) showMediaPicker: (id) sender
{
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
[[picker view] setFrame:CGRectMake(0, 0, 320, 480)];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"AddSongsPrompt", #"Prompt to user to choose some songs to play");
[self presentModalViewController:picker animated: YES];
[picker release];
}
There I tried to set the size to 320x480 but no luck, the picker is still presented and leaves a space in the upper part of the screen, could anyone help me ?
Btw, here's how it looks:
alt text http://img195.imageshack.us/img195/1986/img0001yb.png
I have asked a bit, and people told me this could indeed be a bug, what do you guys think ?
This could go two ways. Yes I'd say it's a bit of a bug that the picker doesn't resize accordingly, but it could also be argued that Apple expects the picker to operate in a non-full screen environment.
Rather than try to force it to work as you'd like, I'd instead recommend turning the status bar back on while the picker is visible:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
(To confirm, you are turing the status bar off in a similar fashion with your app, not just somehow painting over it?)
[[picker view] setBounds:CGRectMake(0, 0, 320, 480)];
Perhaps?
picker.wantsFullScreenLayout = YES;
picker.view.clipsToBounds = NO;