如何在我的 iPhone 应用程序中访问 iPod 库

Posted

技术标签:

【中文标题】如何在我的 iPhone 应用程序中访问 iPod 库【英文标题】:How can I access iPod Library in my iPhone app 【发布时间】:2011-01-24 13:13:48 【问题描述】:

,比如用户在播放时聆听音乐...比如在 gameloft 游戏中,或从 Photos.app 中的幻灯片放映?

【问题讨论】:

【参考方案1】:

看看 MPMusicPlayerController。我读过它可以访问 iPod 库。没用过,不知道能不能帮到你……

【讨论】:

【参考方案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];

【讨论】:

以上是关于如何在我的 iPhone 应用程序中访问 iPod 库的主要内容,如果未能解决你的问题,请参考以下文章

我们可以在 iPhone 应用程序中访问播客吗?

如何在 iPhone 上打开音乐(ipod 库)?

如何在我的 iPod touch 上查看“本地主机”

在我的 iPhone 应用程序中播放 iTunes 歌曲

AddMusic 示例 Ipod 库访问 [关闭]

在我的应用程序中复制 iphone 库的音乐文件