2016-12-17 3 views
0

line inループを使用して別の配列のAVPlayerItemオブジェクトの配列を作成します。これは単一の項目では機能しますが、配列全体では機能しません。iOS - AVQueuePlayer initwithitems()を使用できません

MPMediaQuery *albumQuery = [MPMediaQuery albumsQuery]; 
MPMediaPropertyPredicate *albumPredicate = [MPMediaPropertyPredicate predicateWithValue:@"Out Of Exile" forProperty:MPMediaItemPropertyAlbumTitle]; 
[albumQuery addFilterPredicate:albumPredicate]; 
NSArray *songs = [albumQuery items]; 
NSMutableArray <AVPlayerItem*> *items; 
NSUInteger i = 0; 

while(i < [songs count]){ 
    AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:[[songs objectAtIndex:i] valueForProperty:MPMediaItemPropertyAssetURL]]; 
    [items addObject:playerItem]; 
    i++; 
} 

AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:[[songs objectAtIndex:index] valueForProperty:MPMediaItemPropertyAssetURL]]; //manually created item which works 
_player = [[AVQueuePlayer alloc] initWithItems:items]; 

[_player play]; 

だから、私の問題は、私はきちんとして、配列AVQueuePlayerを初期化することができないということであり、それは私が怒っ駆動です。 InitWithPlayerItemで初期化し、作成したアイテムを追加すると機能しますが、アイテム配列のオブジェクトでは機能しません。

InitWithItems:items[index*]を呼び出しても、何も起こりません。

答えて

1

コードは機能します。

NSMutableArray <AVPlayerItem*> *items = [[NSMutableArray alloc] init]; 

あなたのループに入り、AVQueuePlayerが動作するはずの前に上記の行を追加する:あなたはあなたの配列を初期化するために忘れてしまったので、別の作品の後に手動で1つのitemを追加しながら、動作しませんAVQueuePlayeritemsを追加する理由はあります。

これが役に立ちます。

関連する問題