簡體   English   中英

如何在AVPlayer中使用AVQueuePlayer

[英]how to use AVQueuePlayer in AVPlayer

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

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]];

您可以發布一個更具體的問題(如果有的話),但是文檔應該非常清楚如何開始。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM