Hi everyone,
I'm having an odd issue trying to present an MPMediaPickerController using presentModalViewController. I had it working fine, but recently (perhaps as of 3.1, I don't exactly recall the last time it was working) the MPMediaPickerController just refuses to show itself. The screen just remains black, with nothing but the status bar at the top, and I'm forced to quit the application.
Here's my code:
// Show the music picker, allowing the user to create a playlist
- (void) showMusicPicker;
{
[[Director sharedDirector] pause];
[[Director sharedDirector] detach];
musicView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[window addSubview:musicView];
musicController = [[UIViewController alloc] init];
[musicController setView:musicView];
[musicController setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = @"Select songs to play";
// The media item picker uses the default UI style, so it needs a default-style
// status bar to match it visually
[[UIApplication sharedApplication] setStatusBarHidden:NO animated: YES];
[musicController presentModalViewController: picker animated: YES];
[picker release];
}
As you can see, it's mostly copied verbatim from Apple's examples, with a few modifications to get it to work with Cocos2D. The window variable in the code is the application window, which is retained in the init method:
// Remember the window that the director is attached in
window = [[[[Director sharedDirector] openGLView] window] retain];
The rest of the method appears to work fine... the director detaches from the window and the status bar appears. But then the MPMediaPickerController should appear on the screen, and it doesn't. As I mentioned, it was working fine not too long ago, so I'm at a loss as to what's going on here.
Thanks for any help you can provide.
Edit: I've noticed that if I comment out these lines:
[[Director sharedDirector] pause];
[[Director sharedDirector] detach];
[window addSubview:musicView];
and replace them with:
[[[Director sharedDirector] openGLView] addSubview: musicView]
...then the picker controller is shown as it should be. This was the way I added the view when I was first implementing iPod library access after 3.0 came out, as it's a little less convoluted than the current way. However, the problem with this method is that once the picker controller is dismissed, all the touch coordinates which are reported to me on touch events become inaccurate - they're about 20 pixels higher than they should be (portrait orientation.) I'm not sure if this is a bug with Cocos2D or what, but it pretty much rules out presenting the controller directly on the Director's openGLView.