MusicKit JS: Queue repeats forever in buggy manner

When I run the following code:


await MusicKit.getInstance().setQueue({
  song: appleMusicId,
});

await MusicKit.getInstance().play();


The queued song will repeat indefinitely. Oddly, calling "play" or "pause" after it's repeated will cause an `AbortError` and for the song to be restarted entirely. I've also noticed that the playback state never changes to `MusicKit.PlaybackStates.completed` due to this bug.


This seems like a pretty huge bug. At first I thought it was something wrong in my application logic, but I noticed Zachary Seguin's web player (https://music.zacharyseguin.ca/) has the same issue - try playing a single-song playlist with "Repeat" off and notice it keeps repeating indefinitely. (If you need a short song to test with, might I recommend Sufjan Stevens's six-second "One Last 'Whoo-Hoo!' for the Pullman," which I've listened to approximately 8000 times while debugging this issue)


Hopefully this can be fixed soon. In the meantime, I'm not sure of a good workaround. I've tried resetting the queue after starting playback, but that breaks subsequent play/pause calls. I've tried resetting the queue after the playback ends (using the `PlaybackStates.ended` state), but the song still plays back once more before stopping. My current solution is this awful bit of hackiness:


const onPlaybackStateChange(evt) => {
  if (evt.state === MusicKit.PlaybackStates.ended) {
    // store state to indicate the song has finished playing back
    this.ended = true;
  }
  if (evt.state === MusicKit.PlaybackStates.waiting && this.ended) {
    // the song is trying to restart itself! now we can kill it for good
    MusicKit.getInstance().stop();
  }
};


I'm hopeful there are other ways of manipulating the queue and playback state that could also help with working around this bug. But really, I'm hoping this bug will be fixed and `PlaybackStates.completed` will work properly again.

Replies

This behavior started on 5/22/2019. It never used to happen before. Prior to 5/22/2019, when the song ended, it simply ended. Now, there is the behavior you saw. And no, there seems to be no better solution than yours. In my case, I used pause() on the first playbackTimeDidChange event after playbackStateDidChange event fires with state set to ended, but basically same thing. This is already the second time in the last few months that the behavior upon reaching the end of a song changed and broke all our code. Recommend you submit this issue via Feedback reporter if you haven't already.

Thanks for the suggestion to use the Feedback Assistant; I've submitted it on there now. Hopefully this and the broken Android login get fixed soon.