How to loop a queue of sounds in AVQueuePlayer?

I know a few questions regarding the same problem, but after following these suggestions I came across several problems.

Everything is set up for me, but I get mach errors every time I use kMTTimeZero.

soundQueue = [AVQueuePlayer queuePlayerWithItems:soundEmotions];

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

Here is what I did.

- (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 characters for armv7 architecture: "_kCMTimeZero", link: - [ViewController playerItemDidReachEnd:] in ViewController.o ld: character (s) not found for armv7 architecture clang: error: linker command with exit code 1 (use -v for call call)

+5
source share
2 answers

kCMTimeZero CoreMedia.framework, " " " " .

+17

, 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)
            }
        }
    }

private func observeTrackChanged(of player : AVQueuePlayer) {

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

All Articles