我正在播放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];
}
}