2

目前我正在使用以下代码播放歌曲

playerItem = [AVPlayerItem playerItemWithURL:[song valueForProperty:MPMediaItemPropertyAssetURL]];
    [_avPlayer replaceCurrentItemWithPlayerItem:playerItem];

在这里我使用 AVPlayer 播放音频文件,但我的要求是需要连续播放歌曲组(NSArray)(当前播放器在播放一首歌曲后停止)。我听说过 AVQueuePlayer 但不知道如何使用它与 avplayer如果有人知道,请帮助我

4

1 回答 1

5

查看以下 Apple 文档:https ://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVQueuePlayer_Class/Reference/Reference.html

AVQueuePlayer 的基础与 AVPlayer 没有太大区别。您可以使用 AVPlayerItems 列表初始化播放器,并且将为您处理连续播放。

AVPlayerItem *item1 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://www.playeritemurl.com/item1.aac"]];
AVPlayerItem *item2 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://www.playeritemurl.com/item2.aac"]];
AVPlayerItem *item3 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://www.playeritemurl.com/item3.aac"]];
AVQueuePlayer *player = [[AVQueuePlayer alloc] initWithItems:@[item1, item2, item3]];

如果您有一个更具体的问题,您可以发布一个更具体的问题,但文档应该相当清楚地说明如何开始。

于 2014-04-01T12:16:52.650 回答