<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Web Playback SDK: Detect Track End in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5577651#M9158</link>
    <description>&lt;P&gt;Still appears to be the case as of mid-2023. Unfortunately, the link posted by _lucifer_ appears to still be the best bet when attempting to identify track end, but it usually fires 2-4 times, making it difficult to work with.&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2023 04:09:30 GMT</pubDate>
    <dc:creator>jfk52917</dc:creator>
    <dc:date>2023-05-09T04:09:30Z</dc:date>
    <item>
      <title>Web Playback SDK: Detect Track End</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5391515#M4796</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;India&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Chrome/Firefox Latest&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Ubuntu 22.04&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The Web Playback SDK has no state event for detecting the track end. Some workarounds are listed in &lt;A href="https://github.com/spotify/web-playback-sdk/issues/35" target="_blank"&gt;https://github.com/spotify/web-playback-sdk/issues/35&lt;/A&gt; . But those seem unstable and aren't working properly. What is the right way to detect track end events correctly ?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 19:00:49 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5391515#M4796</guid>
      <dc:creator>_lucifer_</dc:creator>
      <dc:date>2022-06-08T19:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Web Playback SDK: Detect Track End</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5450835#M6862</link>
      <description>&lt;P&gt;Hello, I'm bumping this thread because as far as I know there is still on way to properly detect the end of a track without using a workaround.&lt;BR /&gt;Ideally, there should be an event that we can subscribe to, which would allow more precise control over playback.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 11:56:37 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5450835#M6862</guid>
      <dc:creator>Mordicus</dc:creator>
      <dc:date>2022-10-28T11:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Web Playback SDK: Detect Track End</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5577651#M9158</link>
      <description>&lt;P&gt;Still appears to be the case as of mid-2023. Unfortunately, the link posted by _lucifer_ appears to still be the best bet when attempting to identify track end, but it usually fires 2-4 times, making it difficult to work with.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 04:09:30 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5577651#M9158</guid>
      <dc:creator>jfk52917</dc:creator>
      <dc:date>2023-05-09T04:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Web Playback SDK: Detect Track End</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5587129#M9343</link>
      <description>&lt;P data-unlink="true"&gt;For what it's worth @jfk52917 this is how we debounce this call:&amp;nbsp;&lt;BR /&gt;metabrainz/listenbrainz-server/blob/master/frontend/js/src/brainzplayer/SpotifyPlayer.tsx#L119-L122&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;To then be used with the aforementioned hack:&lt;BR /&gt;metabrainz/listenbrainz-server/blob/master/frontend/js/src/brainzplayer/SpotifyPlayer.tsx#L502-L514&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;EDIT for permalinks (apparently we can't paste GH links anymore, so you'll have to copy-paste):&lt;/P&gt;&lt;P data-unlink="true"&gt;metabrainz/listenbrainz-server/blob/58123bd9b88c6391eb79c7c5b47b864b14daa7d6/frontend/js/src/common/brainzplayer/SpotifyPlayer.tsx#L124-L127&amp;nbsp;&lt;BR /&gt;and&lt;/P&gt;&lt;P data-unlink="true"&gt;metabrainz/listenbrainz-server/blob/58123bd9b88c6391eb79c7c5b47b864b14daa7d6/frontend/js/src/common/brainzplayer/SpotifyPlayer.tsx#L540-L552&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2025 15:38:01 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/5587129#M9343</guid>
      <dc:creator>Mordicus</dc:creator>
      <dc:date>2025-08-12T15:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Web Playback SDK: Detect Track End</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/6712886#M16957</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here's where I'm hoping some smarter people than me can weigh in. There are 2 other potential fixes I have noticed in my testing. Developer Tools are your friend here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://cpapi.spotify.com/v1/client/%7Bclient_id%7D/event/item_end" rel="nofollow noreferrer" target="_blank"&gt;https://cpapi.spotify.com/v1/client/{client_id}/event/item_end&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;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. I presume this is also because it's happening on the hidden iframe and I couldn't figure out how to access it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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. (&lt;A href="https://chromium.googlesource.com/chromium/src/+/refs/heads/main/media/base/media_log_events.h" rel="nofollow noreferrer" target="_blank"&gt;https://chromium.googlesource.com/chromium/src/+/refs/heads/main/media/base/media_log_events.h&lt;/A&gt;) If there's a way to listen for these library calls then that's a possibility too.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 23:10:48 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Web-Playback-SDK-Detect-Track-End/m-p/6712886#M16957</guid>
      <dc:creator>macoirc</dc:creator>
      <dc:date>2025-02-13T23:10:48Z</dc:date>
    </item>
  </channel>
</rss>

