简体   繁体   English

如何在AVPlayer中使用AVQueuePlayer

[英]how to use AVQueuePlayer in AVPlayer

currently i am using following codes to play song 目前我正在使用以下代码播放歌曲

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

here i am using AVPlayer for playing audio files, but my requirement is need to play group (NSArray) of song continuously(currently player stop after playing one song).I heared about AVQueuePlayer but don't know how to use is it with avplayer if anyone know this please help me 我在这里使用AVPlayer播放音频文件,但我的要求是连续播放歌曲组(NSArray)(当前播放一首歌曲后播放器停止播放)。我听说过AVQueuePlayer但不知道如何与avplayer一起使用如果有人知道这一点,请帮助我

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

The basics of AVQueuePlayer are not much different than AVPlayer. AVQueuePlayer的基础与AVPlayer并没有太大区别。 You can initialize your player with a list of AVPlayerItems, and the continuous playback will be handled for you. 您可以使用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]];

You can post a more specific question, if you have one, but the documentation should be fairly clear on how to get started. 您可以发布一个更具体的问题(如果有的话),但是文档应该非常清楚如何开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM