I’m trying to display the music library from the users IOS device to play music, while an app is running. I’m currently doing this by using the main body of my code to call a .mm file, which then calls an Objective C file with the code that displays the IOS library, but it won’t show it because I don’t have direct access to the view I’m trying to add it to. Warning: Attempt to present <MPMediaPickerController: 0x7a0d3120> on <myClass: 0x7a0d2b40> whose view is not in the window hierarchy!
-(void)addMusicBtnAction{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
mediaPicker.delegate = self;
mediaPicker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
for (UIAlertView *alrt in subviews) {
if ([alrt isKindOfClass:[UIAlertView class]]){
if (alrt.tag == 10020) {
[alrt dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
}
[self presentViewController:mediaPicker animated:YES completion:nil];
}