Music Kit JS Reload Page

I'm trying to figure out if an event gets called whenever I'm streaming with the music kit player and I reload the page. I'm using Chrome and when I reload the page the streaming music stops and says the browser prevented playing without user interaction.

Events I have listeners for include:

  • mediaPlaybackError
  • nowPlayingItemDidChange
  • playbackStateDidChange
  • queueIsReady
  • queueItemsDidChange
  • mediaCanPlay

Each of these are associated with a console message so I can track when they get called. This is what appears in my console when I start a playlist:

I thought that the "mediaPlaybackError" would be called but it wasn't, and no other errors seem to pop up. The documentation here: https://developer.apple.com/documentation/musickitjs/musickit/events doesn't really explain much about the events.

Does anyone have a solution for this? I'm not really sure what I should be checking for. I was able to get something like this resolved with Spotify's player with an event that fired off saying the browser prevented playback. Right now I'm testing this by playing a track and then reloading the page. I just need some way to verify that the player has stopped due to a page reload.

I suppose right now my alternative option is to check if the page has reloaded and then restart the Apple music player but that seems like a big workaround for something that should be simple and easy to verify with Music Kit JS.

Thank you for the question, @gonzosan

The DOMException error is thrown by Chrome natively, which is consistent with most browsers; Playback of media content with audio sources requires user interaction first. It cannot be automatically started on page load.

I understand that, I'm asking for something that Music Kit JS can detect this kind of change. Like I mentioned before, with the Spotify player I was using on reload it calls a playback error event then I can prompt the user to play manually. Is there an event or some error that shows up when playback is interrupted on reload?

Thank you for your response, @gonzosan

There is currently no event that captures this particular error that you can key off of to provide better instructions to the user. This would be an excellent enhancement request. If you could please file a ticket in the Feedback Assistant, it will help us prioritize the work.

Music Kit JS Reload Page
 
 
Q