79437863

Date: 2025-02-13 22:25:25
Score: 0.5
Natty:
Report link

This appears to still be an issue in 2025, so rather than post a new question I thought it cleaner to add to this conversation. For now I have settled for adding a sleep into my code to make it wait for the duration of the track. Each track object contains its duration so this is easy enough. But it is a klunky, highly volatile, solution. Pausing the track messes it up, for example.

So here's where hopefully some smarter people can weigh in. There are 2 other potential fixes I have noticed in my testing. Developer Tools are your friend here.

First, the index.js script that gets loaded into the hidden iframe DOES contain definitions for item_end and track_ended. But they don't seem to be emitting to the parent. I don't know if this is a bug or intentional by Spotify. But I do see in the network traffic a POST event from fetch to https://cpapi.spotify.com/v1/client/{client_id}/event/item_end so the event is firing, it's just not getting back to our app code from the embedded player. I wasn't successful in any attempts to intercept that fetch() call as a way to determine the track had ended.

Second, in Chromium-based browsers anyway, the embedded player logs typical events like load, play, pause, and ended, as viewable in the Developer Tools Media tab. (https://chromium.googlesource.com/chromium/src/+/refs/heads/main/media/base/media_log_events.h) If there's a way to listen for these library calls then that's a possibility too.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: MacOirc