AVQueuePlayer.remove stutter

I am trying to play an audio clip in a loop until a different audioclip gets selected. When that happens it should wait for the current audio clip to finish and continue looping with the newly selected clip (gapless).

These audio clips were made to be played in loops and in succession. However it's important that the next clip doesn't start until some condition has been met.

I've tried using AVQueuePlayer which I got working quite well except for one thing, which is that remove(_ item: AVPlayerItem) seems to add a "stutter" to the currently playing clip. Almost like it's buffering or something. Which is strange because all audio files are embedded in the project.

The clips are quite short (between 1 and 2 seconds). How can I get this to work without a stutter? Or maybe using something entirely different even?

Update: I also tried using AVPlayerLooper, which works great with 1 clip but I can't tell it to continue looping using another clip (without a gap).
To clarify: When you remove an item, you're not removing the currently-playing item, correct?
Correct. I am removing everything except the playing item.

When I say everything I mean 1 or 2 items depending on the size of the queue I work with. It's 1, but I also tried it with 2.

I also found this: https://stackoverflow.com/questions/16654300/avqueueplayer-playback-freezes-when-removing-items-from-queue which tells me this issue is not new.

Update

This is the code I run right before I add the next clip. These loops use observers to add a new clip when they end with always two clips in the queue. When a new clip gets added all these observers and the items in the player get removed. After that a new loop (with observers) gets created, so only the currently playing copy remains until the next looping clip starts.

Code Block
func truncate () {
  for observer in observers {
    NotificationCenter.default.removeObserver(observer as Any)
  }
   
  for item in player.items() {
    if (item.isEqual(player.currentItem)) {
      continue
    }
    player.remove(item)
  }
  observers.removeAll()
}

Thanks for the extra detail. I think the best next step would be to file a bug using the feedback assistant, ideally with a test app we can compile to reproduce the issue.

Did you ever end up finding a solution to this issue?

AVQueuePlayer.remove stutter
 
 
Q