Web Playback SDK togglePlay fails to pause track

Web Playback SDK togglePlay fails to pause track

Plan

Premium

Country

US

 

Device

(Macbook Pro late 2016)

Operating System

(macOS Monterey)

 

My Question or Issue

My project is a bit complex and have it hosted in a private GitHub repository unfortunately. Essentially though, here is the issue:

- initialize web SDK with a (premium) user token

- use the web API's /vi/player endpoint to transfer playback to the just initialized device

- use the web API's /v1/player/play endpoint to set the current track

- use the web SDK's player.togglePlay via user click/interaction (or .resume/.pause counterparts) to START playback

- use the web SDK's player.togglePlay via user click/interaction (or .resume/.pause counterparts) to PAUSE playback

- playback pauses for roughly 1 second, then resumes from the beginning of the track

- all subsequent calls to any SDK togglePlay/resume/pause continue this behavior from above

 

Assumptions made

- assumption: web API's /v1/player/play endpoint allows one to set the current track, with an option to also start playback of that track on whatever currently active device is set

- reality: looking at the docs now, it seems like such an option (to play/pause playback as well) doesn't exist. From what I can gather, the correct assumption to have here is that hitting this endpoint will set the current track and implicitly start playback. Incidentally, playback does not start on my active client

 

After writing this issue out, I came up with a solution, but I could use guidance on if this is the suggested approach to take. Once I realized after reading the documentation for /v1/player/play (see: https://developer.spotify.com/documentation/web-api/reference/#/operations/start-a-users-playback) that playback is most likely auto started despite my client not inherently starting playback, I thought maybe if I use the SDK's player.pause() right after hitting /v1/player/play, I could get the player back to an expected/predictable state. This happened to have worked, and now the SDK togglePlay/resume/pause functions work as expected.

 

This feels wrong, but it does work and roughly makes sense (unclear why the weird behavior outlined above occurs and why initialized player acts confused as to the state of the world). Is this the correct approach to take, and if not what is the correct approach?

 

Any guidance here is appreciated. Happy to hop on a zoom call to walk through the issue in more detail, looking at the project/offending code.

Reply
0 Replies

Suggested posts