How can I access iPod Library in my iPhone app

心不动则不痛 提交于 2020-01-06 08:41:32

问题


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 ?


回答1:


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




回答2:


- (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];
}


来源:https://stackoverflow.com/questions/4782377/how-can-i-access-ipod-library-in-my-iphone-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!