how to use AVQueuePlayer in AVPlayer

空扰寡人 提交于 2019-12-24 03:39:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!