问题
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
回答1:
Look at The following Apple documentation: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVQueuePlayer_Class/Reference/Reference.html
The basics of AVQueuePlayer are not much different than AVPlayer. You can initialize your player with a list of AVPlayerItems, and the continuous playback will be handled for you.
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.
来源:https://stackoverflow.com/questions/22619587/how-to-use-avqueueplayer-in-avplayer