Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 334
user2291109 Avatar asked Dec 26 '22 20:12

user2291109


2 Answers

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.

like image 169
wombat57 Avatar answered Dec 28 '22 10:12

wombat57


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.

like image 20
Ed Filowat Avatar answered Dec 28 '22 10:12

Ed Filowat