如何从ipod Library中获取所选歌曲并在UITableView中显示

时间:2012-07-23 16:10:36

标签: objective-c ios xcode avplayer

我正在播放AVPlayer的歌曲,我有uitableview我需要显示来自ipodLibrary的所选歌曲,我检查了从苹果添加音乐项目..他们使用updatePlayerQueueWithMediaCollection方法获取歌曲列表。 现在播放属性可以在mpmusicplayercontroller中找到..所以我想知道如何在使用AVPlayer时显示歌曲。

     if (mediaItemCollection)
     {
         if (userMediaItemCollection == nil)
         { 
        self setUserMediaItemCollection: mediaItemCollection]; 
        [musicPlayer setQueueWithItemCollection: userMediaItemCollection]; 
        [self setPlayedMusicOnce: YES]; 
        [musicPlayer play]; 
        } 
        else { 
        BOOL wasPlaying = NO; 
                }
            if (musicPlayer.playbackState == MPMusicPlaybackStatePlaying) 
        {
         wasPlaying = YES; 
        } 
        MPMediaItem *nowPlayingItem = musicPlayer.nowPlayingItem; 
        NSTimeInterval currentPlaybackTime = musicPlayer.currentPlaybackTime; 
        NSMutableArray *combinedMediaItems = [[userMediaItemCollection items] mutableCopy]; 

            NSArray *newMediaItems = [mediaItemCollection items]; 
        [combinedMediaItems addObjectsFromArray: newMediaItems]; 
        [self setUserMediaItemCollection: [MPMediaItemCollection collectionWithItems: (NSArray *) combinedMediaItems]];

         [musicPlayer setQueueWithItemCollection: userMediaItemCollection]; musicPlayer.nowPlayingItem = nowPlayingItem; 
    musicPlayer.currentPlaybackTime = currentPlaybackTime; 
    if (wasPlaying) 
{ [musicPlayer play];
    } 
    } 

0 个答案:

没有答案