【问题标题】:how to use AVQueuePlayer in AVPlayer如何在 AVPlayer 中使用 AVQueuePlayer
【发布时间】:2014-03-24 20:09:02
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios avplayer avqueueplayer


    【解决方案1】:

    查看以下 Apple 文档:https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVQueuePlayer_Class/Reference/Reference.html

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

    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]];
    

    如果您有一个更具体的问题,您可以发布一个更具体的问题,但文档应该非常清楚地说明如何开始。

    【讨论】:

    • 我已经创建了队列并在其中添加了 playerItems。我调用了 queue.play(),但不知道如何设置框架并且无法在屏幕上看到任何东西(调用 Play 方法没有任何错误)请指导我
    • 我尝试使用 AVPlayerLayer 并在其中添加了队列。然后设置该层的框架并将其添加为我的视图的子层。但是现在它没有任何播放器控件+图层的框架设置不正确。
    • 我会尝试查找代码。恐怕,已经4年了。我不确定我是否有该代码 atm
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 2016-09-10
    • 2016-08-08
    相关资源
    最近更新 更多