如何在AVPlayer中使用AVQueuePlayer [英] how to use AVQueuePlayer in AVPlayer

查看:86
本文介绍了如何在AVPlayer中使用AVQueuePlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我正在使用以下代码播放歌曲

currently i am using following codes to play song

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

我在这里使用AVPlayer播放音频文件,但我的要求是连续播放歌曲组(NSArray)(当前播放器在播放一首歌曲后停止).我听说过AVQueuePlayer,但不知道如何使用如果有人知道,请与avplayer一起使用,请帮助我

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

推荐答案

查看以下Apple文档:

Look at The following Apple documentation: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVQueuePlayer_Class/Reference/Reference.html

AVQueuePlayer的基础知识与AVPlayer并没有太大区别.您可以使用AVPlayerItems列表初始化播放器,然后将为您处理连续播放.

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.

这篇关于如何在AVPlayer中使用AVQueuePlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆