我的播放器在播放第一首歌曲后停止 [英] My player stops after playing first song

查看:29
本文介绍了我的播放器在播放第一首歌曲后停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从 ipod 库中选择多首歌曲时,我正在使用 AVPlayer,一旦第一首歌曲播放完毕,这些选定的歌曲就会显示在名为 playlistTableView 的 UITableview 中,但不会继续播放第二首歌曲.我希望播放器继续播放直到 playlistTableView 中没有歌曲为止.

I am using AVPlayer when i select multiple songs from my ipod library ,those selected songs are displayed in a UITableview called playlistTableView as soon as the first song plays out it doesnt continue with second song .. I want the player to continue playing songs till there are no songs left in playlistTableView .

推荐答案

在 iOS 4.1 及更高版本上,您可以使用 AVQueuePlayer 对象按顺序播放多个项目.AVQueuePlayer 是 AVPlayer 的子类.您使用一系列播放器项目初始化队列播放器:

On iOS 4.1 and later, you can use an AVQueuePlayer object to play a number of items in sequence. AVQueuePlayer is a subclass of AVPlayer. You initialize a queue player with an array of player items:

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

<小时>

然后您可以使用 play 播放队列,就像您使用 AVPlayer 对象一样.队列播放器依次播放每个项目.如果您想跳到下一个项目,您可以向队列播放器发送一条 AdvanceToNextItem 消息.您可以使用 insertItem:afterItem:、removeItem: 和 removeAllItems 修改队列.添加新项目时,您通常应该检查它是否可以插入队列,使用 canInsertItem:afterItem:.您将 nil 作为第二个参数传递以测试是否可以将新项添加到队列中:


You can then play the queue using play, just as you would an AVPlayer object. The queue player plays each item in turn. If you want to skip to the next item, you send the queue player an advanceToNextItem message. You can modify the queue using insertItem:afterItem:, removeItem:, and removeAllItems. When adding a new item, you should typically check whether it can be inserted into the queue, using canInsertItem:afterItem:. You pass nil as the second argument to test whether the new item can be appended to the queue:

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

有关详细信息,请参阅以下文档.

For more information, please see the following documentation.

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

这篇关于我的播放器在播放第一首歌曲后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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