简体   繁体   English

如何在AVQueuePlayer中循环声音队列?

[英]How do I loop the queue of sounds in AVQueuePlayer?

I know multiple questions concerning the same issue exist, but after following this one's suggestions, I run into a couple of problems. 我知道存在关于同一问题的多个问题,但在遵循这个建议之后,我遇到了一些问题。

I have everything set up but I get to mach errors everytime I use kMTTimeZero. 我已经完成了所有设置但每次使用kMTTimeZero时我都会遇到马赫错误。

soundQueue = [AVQueuePlayer queuePlayerWithItems:soundEmotions];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playerItemDidReachEnd:)
                                                 name:AVPlayerItemDidPlayToEndTimeNotification
                                               object:[soundEmotions lastObject]];

Here's what I've done . 这就是我所做的。

- (void)playerItemDidReachEnd:(NSNotification *)notification {
    // Do stuff here
    NSLog(@"End has been reached.");

    // Set it back to the beginning
    [soundQueue seekToTime:kCMTimeZero];

    //Replay
    [soundQueue play];

}

ERROR: Undefined symbols for architecture armv7: "_kCMTimeZero", referenced from: -[ViewController playerItemDidReachEnd:] in ViewController.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation) 错误:架构armv7的未定义符号:“_kCMTimeZero”,引用自: - ViewController中的[ViewController playerItemDidReachEnd:] ld:未找到架构armv7 clang的符号:错误:链接器命令失败,退出代码为1(使用 - v看看调用)

kCMTimeZeroCoreMedia.framework中的符号,因此您必须将此框架添加到目标的“构建阶段”中的“链接二进制库”部分。

I am using this approach to observe last item and then seek to kCMTimeZero 我使用这种方法观察最后一项 ,然后seek to kCMTimeZero

 override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

        if keyPath == "currentItem" {

            print("Next Track...", currentTrackIndex)

            if currentTrackIndex > 0 {
                self.isPlaying = true
            }

            currentTrackIndex += 1
            if currentTrackIndex > playerQueue.items().count {
                currentTrackIndex = 0
                playerQueue.seek(to: kCMTimeZero)
            }
        }
    }

And then 然后

private func observeTrackChanged(of player : AVQueuePlayer) {

        player.addObserver(self, forKeyPath: "currentItem", options: .new, context: nil)
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM