关于ios:如何在AVPlayer中使用AVQueuePlayer

how to use AVQueuePlayer in AVPlayer

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

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

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


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

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

1
2
3
4
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]];

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