Posts

Post not yet marked as solved
2 Replies
1.2k Views
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.
Posted
by tboyt.
Last updated
.