2014-03-24 25 views
2

目前我使用下面的代碼來播放歌曲如何使用AVQueuePlayer在AVPlayer

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

這裏我使用AVPlayer用於播放音頻文件,但我的要求是需要不斷地播放歌曲的組(NSArray的)(播放一首歌曲)後目前的球員停止。我heared約AVQueuePlayer,但不知道如何使用它是與avplayer如果有人知道這個請大家幫我

回答

5

看看下面的蘋果文檔:https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVQueuePlayer_Class/Reference/Reference.html

的基礎知識的AVQueuePlay呃和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]]; 

您可以發佈更具體的問題,如果您有問題,但文檔應該對如何入門相當清楚。

+0

我已經創建了隊列並在其中添加了playerItems。我調用了queue.play(),但不知道如何設置框架並無法在屏幕上看到任何東西(播放方法被調用時沒有任何錯誤) 請引導我 –

+0

我試圖使用AVPlayerLayer並添加隊列在那裏面。然後設置該圖層的框架並將其添加爲我的視圖的子圖層。但現在它沒有任何播放器控制+圖層的框架設置不正確。 –