<?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: Logic behind progress bar updates in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5237149#M2949</link>
    <description>&lt;P&gt;Just to clarify, on my snippet in my 1st message. The &lt;EM&gt;`state.position`&lt;/EM&gt; is derived from: &lt;A href="https://developer.spotify.com/documentation/web-playback-sdk/reference/#event-player-state-changed" target="_blank" rel="noopener"&gt;event-player-state-changed&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That event is fired when the song changes, play/pause, or at random intervals.&lt;BR /&gt;When that event fires, it will update / correct the position. And simultaneously the timer will add progress to it.&lt;BR /&gt;&lt;BR /&gt;I have had that running for a quite a while, and can't really get it out-of-sync.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jul 2021 08:49:02 GMT</pubDate>
    <dc:creator>Anent</dc:creator>
    <dc:date>2021-07-20T08:49:02Z</dc:date>
    <item>
      <title>Logic behind progress bar updates</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5232408#M2839</link>
      <description>&lt;P&gt;How does one update the progress bar?&lt;BR /&gt;&lt;BR /&gt;Are we supposed to poll the API (ttps://api.spotify.com/v1/me/player/)&lt;/P&gt;&lt;P&gt;every X milliseconds and update the UI?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 14:41:14 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5232408#M2839</guid>
      <dc:creator>sqram</dc:creator>
      <dc:date>2021-07-08T14:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Logic behind progress bar updates</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5232716#M2846</link>
      <description>&lt;P&gt;Not sure what SDK you are using. But on the Web Playback SDK, the player will update it's state whenever user interacts with it or the song changes. Then I created my own loop to just mimic the progress of the song if the song is playing - no need to poll. And it will update itself when the player state updates.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;$: position = state.position;
onInterval(() =&amp;gt; position += state.paused ? 0 : 300, 300);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Above snippet is svelte, but the logic is:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;position updates to state.position when state.position changes.&lt;/LI&gt;&lt;LI&gt;Every 300ms position is updated by 300 - aka. creating an progress bar.&lt;/LI&gt;&lt;LI&gt;If the player is paused. No progress will be added.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Above state object is:&amp;nbsp;&lt;A href="https://developer.spotify.com/documentation/web-playback-sdk/reference/#object-web-playback-state" target="_blank" rel="noopener"&gt;WebPlaybackState Object&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 07:46:26 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5232716#M2846</guid>
      <dc:creator>Anent</dc:creator>
      <dc:date>2021-07-09T07:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: Logic behind progress bar updates</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5233236#M2863</link>
      <description>&lt;P&gt;So what i'm doing right now is, after API call to play the song is made, I start a setInterval to update the progress bar every 100ms.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But setInterval isn't exactly reliable in since JS is single-threaded. Was wondering if there's a more accurate, fail-safe way &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Looks like this is the way to go. thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jul 2021 14:42:46 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5233236#M2863</guid>
      <dc:creator>sqram</dc:creator>
      <dc:date>2021-07-10T14:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Logic behind progress bar updates</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5236230#M2937</link>
      <description>&lt;P&gt;I do a bit of both. I guess where the progress should be based on an interval, then periodically get the actual progress and update. About every 5 seconds currently but looking to tune the interval logic to consider actual start time and current time, things like that&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jul 2021 21:58:07 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5236230#M2937</guid>
      <dc:creator>marklegosz</dc:creator>
      <dc:date>2021-07-17T21:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Logic behind progress bar updates</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5237149#M2949</link>
      <description>&lt;P&gt;Just to clarify, on my snippet in my 1st message. The &lt;EM&gt;`state.position`&lt;/EM&gt; is derived from: &lt;A href="https://developer.spotify.com/documentation/web-playback-sdk/reference/#event-player-state-changed" target="_blank" rel="noopener"&gt;event-player-state-changed&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That event is fired when the song changes, play/pause, or at random intervals.&lt;BR /&gt;When that event fires, it will update / correct the position. And simultaneously the timer will add progress to it.&lt;BR /&gt;&lt;BR /&gt;I have had that running for a quite a while, and can't really get it out-of-sync.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 08:49:02 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5237149#M2949</guid>
      <dc:creator>Anent</dc:creator>
      <dc:date>2021-07-20T08:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Logic behind progress bar updates</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5238496#M2979</link>
      <description>&lt;P&gt;Ooohhh yes. this helped tremendously. thanks for clarifying that!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 01:47:24 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Logic-behind-progress-bar-updates/m-p/5238496#M2979</guid>
      <dc:creator>sqram</dc:creator>
      <dc:date>2021-07-23T01:47:24Z</dc:date>
    </item>
  </channel>
</rss>

