user2291109
user2291109

Reputation: 79

MPMediaPickerController - iOS7

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.

Upvotes: 4

Views: 5346

Answers (6)

Neo101
Neo101

Reputation: 33

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???

Upvotes: 1

Justin Whitney
Justin Whitney

Reputation: 1272

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.

Upvotes: 2

wombat57
wombat57

Reputation: 1341

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.

Upvotes: 4

Abel Domingues
Abel Domingues

Reputation: 51

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…

Upvotes: 1

Payne Chu
Payne Chu

Reputation: 573

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

Upvotes: 0

Ed Filowat
Ed Filowat

Reputation: 414

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.

Upvotes: 2

Related Questions