MPMedia Player Set Queue

I am using a media player to play songs. Setting Queue firstly and start playing songs works fine. While if I try to change the queue when one song is playing queue does not get changed. Until I call the MediaPlayer Play function again.
Calling the Media Player Play function whereas freezes the app for seconds.
Tried several ways but nothing works. Do let me know how we can change the queue of the media player while not disturbing the ongoing song.
Thanks in advance.

Use the prepend function as such:

let descriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [song.id])
musicPlayerController.prepend(descriptor)

Hello @ManishaJoshi,

If you're trying to replace the playback queue with different items and start playing those new items immediately (thus interrupting the song that's already playing), you can indeed call setQueue().

However, the best practice is not to call play() directly after setQueue(); instead, you should call prepareToPlay(), and in the completion handler you pass to that method, if the error argument is equal to nil, then call play() at that point.

Doing so will ensure that you don't block your app's main thread.

That said, if you want to add something to play next without stopping playback of the currently playing song, then you can follow @jackvanderpump's advice of using the prepend() method.

I hope this helps.

Best regards,

MPMedia Player Set Queue
 
 
Q