0

How access iPod Library in my iPhone app, like to the user listem music when is playing... like in the gameloft games, or the slide show from the Photos.app ?

Rafael
  • 83
  • 4
  • 10

2 Answers2

0
- (void)addMusicBtnAction{
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
    mediaPicker.delegate = self;
    //mediaPicker.prompt = @"Select Audio";
    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 presentModalViewController:mediaPicker animated:YES];
    //[mediaPicker release];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
    NSArray * SelectedSong = [mediaItemCollection items];
    if([SelectedSong count]>0){
        MPMediaItem * SongItem = [SelectedSong objectAtIndex:0];
        NSURL *SongURL = [SongItem valueForProperty: MPMediaItemPropertyAssetURL];

        NSString *str = [NSString stringWithFormat:@"%@",SongURL];
        appDelegate.musicFilePath = str;
                //NSLog(@"Audio Loaded");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your audio has been selected"  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil, nil];
        alert.tag = 78787878;
        [alert show];
       // [alert release];
    }

    [self dismissModalViewControllerAnimated: YES];   
}
// Responds to the user tapping done having chosen no music.
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {

    [self dismissModalViewControllerAnimated: YES];

    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}
MCKapur
  • 9,087
  • 9
  • 57
  • 100
BADRI
  • 1,085
  • 8
  • 25
0

Look at MPMusicPlayerController. I read it can access the iPod library. I never used it, and I don't know if it can help you...

sui
  • 68
  • 1
  • 8