<?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: Adding mediaSession support in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/5317277#M3803</link>
    <description>&lt;P&gt;Is there any update about this issue. Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Dec 2021 13:03:09 GMT</pubDate>
    <dc:creator>seckinbrke</dc:creator>
    <dc:date>2021-12-18T13:03:09Z</dc:date>
    <item>
      <title>Adding mediaSession support</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/4954537#M140</link>
      <description>&lt;P&gt;Copy of &lt;A href="https://github.com/spotify/web-playback-sdk/issues/105" target="_blank" rel="noopener"&gt;https://github.com/spotify/web-playback-sdk/issues/105&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Chrome recently rolled out some UI feature related to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/API/MediaSession" target="_blank" rel="nofollow noopener"&gt;mediaSession&lt;/A&gt;, which displays some information about the track we are playing and provides some navigation UI.&lt;/P&gt;&lt;P&gt;As the "audio" element lives within an iframe that is on an external cross-origin URL, there is no way to add something like this to it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let remoteNavigator = window.document.querySelector('iframe').contentWindow.navigator;
remoteNavigator .mediaSession.playbackState = 'playing';
remoteNavigator.mediaSession.metadata = new MediaMetadata({
    title: songMetadata.name,
    artist: (songMetadata?.artists ?? [])
      .map(artist =&amp;gt; artist.name)
      .join(' - '),
    album: songMetadata?.album?.name,
    artwork: (songMetadata?.album?.images ?? []).map(el =&amp;gt; ({
      sizes: el.width + 'x' + el.height,
      src: el.url,
      type: ''
}))&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;&lt;/P&gt;&lt;P&gt;I believe there is value (in my case, at least), to let developers write that mediaSession themselve (instead of forcing it yourself).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I'm not mistaken, spotify-player.js player could act as a bridge between the iframe containing the audio tag and our applications.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd suggest the following API:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Spotify.Player.mediaSession#setPlaybackState&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Set the MediaSessionPlaybackState which can be 'playing', 'paused', or 'none'.&lt;/P&gt;&lt;P&gt;Code Sample: player.mediaSession.setPlaybackState('playing')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Spotify.Player.mediaSession#setMetadata&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Set the MediaMetadata&lt;/P&gt;&lt;P&gt;Code Sample: player.mediaSession.setMetadata(new MediaMetadata({/* ... */}))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bonus point: support for setActionHandler:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Spotify.Player.mediaSession#setActionHandler&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Behaves like setActionHandler of the mediaSession.&lt;/P&gt;&lt;P&gt;Code Sample: player.mediaSession.setActionHandler('nexttrack', /* my callback */);&lt;/P&gt;</description>
      <pubDate>Sun, 24 May 2020 18:47:28 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/4954537#M140</guid>
      <dc:creator>UlysseM</dc:creator>
      <dc:date>2020-05-24T18:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Adding mediaSession support</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/5060966#M1426</link>
      <description>&lt;P&gt;We need this soon as possible. Its just improves so much the user experience. By the way, I try to&amp;nbsp;&lt;SPAN&gt;replicate your code that access the iframe element and set there the mediaSession, but this gives me a security error... I tried to place a silent audio on the background, but the spotify player just override mine. So for now I don't have any solutions to make this essential feature real.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 04:15:13 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/5060966#M1426</guid>
      <dc:creator>joao__vct</dc:creator>
      <dc:date>2020-10-27T04:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding mediaSession support</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/5317277#M3803</link>
      <description>&lt;P&gt;Is there any update about this issue. Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Dec 2021 13:03:09 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/5317277#M3803</guid>
      <dc:creator>seckinbrke</dc:creator>
      <dc:date>2021-12-18T13:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Adding mediaSession support</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/5386387#M4679</link>
      <description>&lt;P&gt;Hello, I was able to set a custom MediaSession. However it's pretty "complicated" and require to customize the iframe (which Spotify probably doesnt allow in their ToS).&lt;/P&gt;&lt;P&gt;If you are interested here is the link to my repo:&amp;nbsp;&lt;A href="https://github.com/RichardDorian/Lightify" target="_blank"&gt;https://github.com/RichardDorian/Lightify&lt;/A&gt;&lt;BR /&gt;And if you want to try out by yourself you can go here:&amp;nbsp;&lt;A href="https://richarddorian.github.io/Lightify/" target="_blank"&gt;https://richarddorian.github.io/Lightify/&lt;/A&gt;&amp;nbsp;(you'll need an auth token because I didn't do auth stuff)&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 18:02:26 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Adding-mediaSession-support/m-p/5386387#M4679</guid>
      <dc:creator>DorianRichard</dc:creator>
      <dc:date>2022-05-25T18:02:26Z</dc:date>
    </item>
  </channel>
</rss>

