2012-07-26 144 views
0

我使用AVPlayer時,當我從我的iPod庫中選擇多首歌曲時,只要第一首歌曲播放出來,那些選定的歌曲就會顯示在名爲playlistTableView的UITableview中,不會繼續播放第二首歌曲。我希望播放器繼續播放歌曲,直到playlistTableView中沒有歌曲。播放第一首歌曲後,我的播放器停止播放

+0

什麼是你的代碼傳遞歌曲播放給玩家? – rdelmar 2012-07-26 03:39:26

+0

NSURL * assetUrl = [mediaItemCollection.representativeItem valueForProperty:MPMediaItemPropertyAssetURL]; AVRLAsset * asset = [AVURLAsset URLAssetWithURL:assetUrl options:nil]; //創建播放器項目 AVPlayerItem * playerItem = [AVPlayerItem playerItemWithAsset:asset]; [code] //播放 myPlayer = [AVPlayer playerWithPlayerItem:playerItem]; collectionMutableCopy = [mediaItemCollection.items mutableCopy]; [self.myPlaylistTable reloadData]; [myPlayer play]; 這是我的代碼 – coded 2012-07-26 05:20:17

回答

1

在iOS 4.1及更高版本中,可以使用AVQueuePlayer對象按順序播放多個項目。 AVQueuePlayer是AVPlayer的一個子類。您初始化一個隊列球員與球員元素的數組:

NSArray *items = <#An array of player items#>; 
AVQueuePlayer *queuePlayer = [[AVQueuePlayer alloc] initWithItems:items]; 

您可以使用播放然後播放隊列,就像你的AVPlayer對象。隊列播放器依次播放每個項目。如果您想跳到下一個項目,則向隊列播放器發送advanceToNextItem消息。 您可以使用insertItem修改隊列:afterItem :, removeItem :,和removeAllItems。添加新項目時,通常應使用canInsertItem:afterItem:檢查是否可以插入到隊列中。您傳遞零作爲第二個參數來測試新項目是否可以附加到隊列:

AVPlayerItem *anItem = <#Get a player item#>; 
if ([queuePlayer canInsertItem:anItem afterItem:nil]) 
{ 
    [queuePlayer insertItem:anItem afterItem:nil]; 
} 

欲瞭解更多信息,請參閱下面的文檔。

http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188

+1

NSURL * assetUrl = [mediaItemCollection.representativeItem valueForProperty:MPMediaItemPropertyAssetURL]; AVURLAsset * asset = [AVURLAsset URLAssetWithURL:assetUrl options:nil]; //創建播放器項AVPlayerItem * playerItem = [AVPlayerItem playerItemWithAsset:asset]; [code] //播放myPlayer = [AVPlayer playerWithPlayerItem:playerItem]; collectionMutableCopy = [mediaItemCollection.items mutableCopy]; [self.myPlaylistTable reloadData]; [myPlayer play];這是我的代碼 – coded 2012-07-26 06:37:38

相關問題