kCMTimeZero
is a symbol in the CoreMedia.framework, therefore you have to add this framework to the "Link Binary With Libraries" section in the "Build Phases" of your target.
How do I loop the queue of sounds in AVQueuePlayer?
-
23-03-2022 - |
Question
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.
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)
Solution
OTHER TIPS
I am using this approach to observe last item and then 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)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow