4

I developed test application on iOS 7 that pick the music from music library using MPMediaPickerController. But when I present the media picker controller,it shows empty screen. This is the code

(void) pickSong
{
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = NO;
    mediaPicker.prompt = NSLocalizedString(@"Select Your Favourite Song!", nil);
    [mediaPicker loadView];
    [self.navigationController presentViewController:mediaPicker animated:YES completion:nil];
}

#pragma mark - MPMediaPickerController delegate

(void) mediaPicker:(MPMediaPickerController *) mediaPicker2 didPickMediaItems:(MPMediaItemCollection *) mediaItemCollection {
    [self dismissViewControllerAnimated:YES completion:nil];

    MPMediaItem *mediaItem = [[mediaItemCollection items] objectAtIndex:0];
    self.item.soundName = [mediaItem valueForProperty:MPMediaItemPropertyTitle];
    self.item.soundUrl = [[mediaItem valueForProperty:MPMediaItemPropertyAssetURL] absoluteString];
}

(void) mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker{
    [self dismissViewControllerAnimated:YES completion:NULL];
}

Please help me out.

Michael
  • 57,169
  • 9
  • 80
  • 125
user2291109
  • 79
  • 1
  • 2
  • 6

6 Answers6

4

This is an iOS bug, but it only occurs when running a 32 bit build on a 64 bit (A7) device (Only iPhone 5S for now). To work around it, add a 64 bit architecture to your app. (Open build settings in xcode, and change Architecture from $ARCHS_STANDARD to $ARCHS_STANDARD_INCLUDING_64_BIT.) You will then probably need to fix a number of compile, link and runtime issues. See Apple's 64-Bit Transition Guide.

wombat57
  • 1,341
  • 1
  • 13
  • 26
  • nice try.. but this bug is happening on my iPod touch 5G device, which has an A5 chip which [is a 32 bit processor](https://en.wikipedia.org/wiki/Apple_A5) – abbood Jul 11 '15 at 09:16
2

Seems like there is a bug in ios7 where it doesn't like to be presented inside a uinavigation controller - try presenting it directly from a view controller.

Ed Filowat
  • 404
  • 5
  • 8
2

I had the same problem and for me the solution was a combination of two of the solutions presented here. First I had to convert my app to be 64-bit ready by changing Architectures to "standard... (including 64-bit)". Once I corrected all the warnings that caused, I had to change the MPMediaPickerController to be presented modally rather than on the navigation stack:

- (IBAction)didSelectMusicPicker:(id)sender {
    MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

    picker.delegate                     = self;
    picker.allowsPickingMultipleItems   = YES;
    picker.prompt                       = NSLocalizedString (@"Add songs to play", "Prompt in media item picker");

    //[self.navigationController pushViewController:picker animated:YES];
    [self presentViewController:picker animated:TRUE completion:NULL];
}

Of course, I also needed to change mediaPicker:didPickMediaItems: and mediaPickerDidCancel: to use dismissViewControllerAnimated. Once all that was fixed, the picker worked as expected on both iPhone 4 and iPhone 5S running iOS 7.

Justin Whitney
  • 1,242
  • 11
  • 17
1

a thought: is the presented screen completely empty, or are you getting the navigation bar at the bottom but with no tracks listed? I've noticed that as of iOS 7 the picker now defaults to opening to the Playlist tab (it used to open to Albums, if I recall)… if you have no playlists on the device that would account for the empty screen…

1

I can see the list of songs and select the songs. But I cannot dismiss the view controller on pressing "Done". I've tried PresentViewController since Modal controller is deprecated.

- (IBAction) showMediaPicker: (id) sender {

    picker =
    [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];

    picker.delegate                     = self;
    picker.allowsPickingMultipleItems   = YES;
    picker.prompt                       = NSLocalizedString (@"AddSongsPrompt", @"Prompt to user to choose some songs to play");

    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated:YES];
    [self.picker removeFromParentViewController];
  [self presentViewController:picker animated:YES completion:nil];
   // [picker release];
}


// Responds to the user tapping Done after choosing music.
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
    [self.picker removeFromParentViewController];
        [self dismissViewControllerAnimated:YES completion:nil];
   //
    [self.delegate updatePlayerQueueWithMediaCollection: mediaItemCollection];
   // [self.mediaItemCollectionTable reloadData];

   // [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}

I've tried RemovefromSuperview also, nothing seems to work. I'm testing this on an iPhone 6 simulator and an iPhone 5 with iOS 8.1.3.

Anyone???

Neo101
  • 33
  • 3
0

I also have the same problem before. But I found out just need to restart the device after upgrade. The music picker appear again.

Payne Chu
  • 543
  • 1
  • 5
  • 15
  • I've tested with another device, but it's same. and it happens same thing in emulator, too – user2291109 Sep 24 '13 at 03:29
  • Simulator never support MPMediaPickerController. You need to test it in device. Have you manually restart your device after upgrade to iOS7? – Payne Chu Sep 24 '13 at 04:37
  • @PayneChu i've never seen anyone receive a vote up for a "restart" answer on stackoverflow.. _ever_ – abbood Jul 11 '15 at 09:29