Swift MPMusicPlayerController ApplicationQueuePlayer skipToNextItem() function causes the queue to be cleared

418 Views Asked by At

I'm working on a music playing app that shows a list of Apple Music songs in a TableView and plays them in a certain order, but am having issues with the MPMusicPlayerController's application queue player. Due to the requirements of the app, I can only prepend one song to the music player's queue in addition to the currently playing song. Essentially, I start the music with two tracks, one playing and one up next. When a song ends, the up next song starts and the next in the song list is added to the player's queue with the prepend() method.

The issue I'm seeing with this is the skipToNextItem() method. Whenever I skip a currently playing song, I get the following error stack trace:

 Queue[22723:4355683] [SDKPlayback] -
[MPMusicPlayerController prependQueueDescriptor] completed id=applicationMusicPlayer error:
Error Domain=MPCPlayerRequestErrorDomain Code=1000 
"Failed to send command 125" 
UserInfo= { 
   NSDebugDescription=Failed to send command 125, NSUnderlyingError=0x2809fa2b0 {
             Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 125 (MRSendCommandError = 7)" 
             UserInfo= { NSDebugDescription=Failed to send command 125 (MRSendCommandError = 7) }
            }
      }

The song that is up next when the skip action is performed does play as it should. However, once that new song finishes, the player's queue is empty, so the player acts like it reached the end of its song list. It gets paused and whatever song played when play() was first called becomes the currently playing track.

Allowing the songs to play completely through works fine; the next song starts playing and a song comes off the top of the list to be prepended in the queue. It's only when skipping a track does this issue occur. I've looked through the documentation for the music player, as well as S/O and the developer forums, to no avail. Any ideas or thoughts on this behavior and/or error message would be greatly appreciated!

0

There are 0 best solutions below