简体   繁体   中英

How can I access iPod Library in my iPhone app

如何在我的iPhone应用程序中访问iPod Library(例如在播放游戏时向用户播放音乐),例如在Gameloft游戏中,或从Photos.app中播放幻灯片?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM