Ios 播放AVQueuePlayer的第n项

Ios 播放AVQueuePlayer的第n项,ios,objective-c,cocoa-touch,avqueueplayer,Ios,Objective C,Cocoa Touch,Avqueueplayer,我有一个AVQueuePlayer的实例,我使用AVPlayerItem的视频集合初始化了它(假设我有10个项目),在一个按钮事件中,我需要播放集合中第n个索引的项目 我使用了-(void)replaceCurrentItemWithPlayerItem:(AVPlayerItem*)项,但它用传递的AVPlayerItem替换了当前播放项 我需要播放AVQueuePlayer的第n个AVPlayerItem。任何帮助都将不胜感激 -(void)播放音频索引:(NSInteger)索引 - (v

我有一个
AVQueuePlayer
的实例,我使用
AVPlayerItem
的视频集合初始化了它(假设我有10个项目),在一个按钮事件中,我需要播放集合中第n个索引的项目

我使用了
-(void)replaceCurrentItemWithPlayerItem:(AVPlayerItem*)项
,但它用传递的
AVPlayerItem
替换了当前播放项

我需要播放
AVQueuePlayer
的第n个
AVPlayerItem
。任何帮助都将不胜感激

-(void)播放音频索引:(NSInteger)索引
- (void)playAudioAtIndex:(NSInteger)index
{
    [player removeAllItems];
    for (int i = index; i <playerItems.count; i ++) {
        AVPlayerItem* obj = [playerItems objectAtIndex:i];
        if ([player canInsertItem:obj afterItem:nil]) {
        [obj seekToTime:kCMTimeZero];
        [player insertItem:obj afterItem:nil];
        }
    }
}
{ [player removeAllItems]; 对于(int i=指数;i两个想法,未经测试:

A.前进

NSUInteger indexToPlay = …
AVPlayerItem *currentItem = [queuePlayer currentItem];
NSUInteger currentIndex = [[queuePlayer items] indexOfObject:currentItem];
for (;currentIndex<indexToPlay; currentIndex++)
{
  [queuePlayer advanceToNextItem];
}
NSUInteger indexToPlay=…
AVPlayerItem*currentItem=[queuePlayer currentItem];
NSUInteger currentIndex=[[queuePlayer项目]索引对象:currentItem];

对于(;currentIndexTried B选项,但它会导致崩溃,因为AVPlayerItem.duration会导致NAN coz,其状态尚未就绪,因此玩家不会寻找时间,应用程序会崩溃。Did尝试观察当前项目的状态,然后计算寻找时间,但它也不起作用。选项A正在打开。非常感谢:)如果播放项目位于当前项目的下一个,此解决方案将起作用。我们要播放的项目是否在后面呢?@FadiAbuzant您最好搜索与播放上一个项目相关的其他答案。这里有很多答案,例如,如果用户点击上一个项目,更新AVQueuePlayer的内容也会有帮助,因此nks:)