目前我正在使用以下代码来播放歌曲
playerItem = [AVPlayerItem playerItemWithURL:[song valueForProperty:MPMediaItemPropertyAssetURL]];
[_avPlayer replaceCurrentItemWithPlayerItem:playerItem];
这里我使用 AVPlayer 来播放音频文件,但我的要求是需要连续播放一组(NSArray)歌曲(当前播放器在播放一首歌曲后停止)。我听说过 AVQueuePlayer 但不知道如何使用与 avplayer 一起使用,如果有人知道请帮助我
最佳答案
查看以下 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]];
如果您有一个更具体的问题,您可以发布一个更具体的问题,但文档应该相当清楚地说明如何开始。
关于ios - 如何在AVPlayer中使用AVQueuePlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22619587/