Media plugin issues

Hi, I am trying to make a plugin, that will allow me to control Spotify, I am stuck with an issue however, that I am unable to see any changes in the UI (using the MediaPlayerDetails.xaml) except the volume control which works as expected.

This is how I am setting the playback state inside the onPoll method:

  var currentAccessToken = getAccessToken();

  var baseUrl = 'https://api.spotify.com/v1/me/player?market=ES';
  var httpHeaders = {
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
      Authorization: 'Bearer ' + currentAccessToken,
    },
  };
  var result = http.get(baseUrl, httpHeaders);

  if (result.data) {
    var deviceId = result.data.device.id;
    var volume = result.data.device.volume_percent;
    var isPlaying = result.data.is_playing;
    var imageUri = result.data.item.album.images[0].url

    plugin.Devices[deviceId].Volume = volume;
    plugin.Devices[deviceId].PlaybackStatus = isPlaying ? 'Play' : 'Stop';
    plugin.Devices[deviceId].AudioTrackData = { Title: 'Title', AlbumArtUri: imageUri };
  }
}

The tile is working propperly, it is showing whether the track is playing or not, also the volume inside the MediaPlayerDetail is working propperly but I cant see any other data.

I don’t remember off the top of my head but I think there’s currently an issue with JSON assignments to AudioTrackData using a plugin. I believe you have to do it something like this:

plugin.Devices[deviceId]["AudioTrackData.Title"] = "title";
plugin.Devices[deviceId]["AudioTrackData.AlbumArtUri"] = "your_uri";

Thanks for your quick response, It is working now with your provided example, I just have one small issue, the Stop and Play buttons are not being displayd inside the details, also the forward, backwards buttons are disabled, do I have to set some other properties to make them work?

I have tried setting the SupportedMediaCommands parameter, but it does not seem to be working :thinking:

Those are dependent on PlaybackStatus & SupportedMediaCommands. You can open “MediaPlayerDetails.xaml” & examine it to find out exactly which values. For example, I know those forward & backwards buttons need SkipBackward & SkipForward.

plugin.Devices[deviceId].SupportedMediaCommands = ["SkipBackward", "SkipForward"];

@bill I have the controls part figured out, thanks for your response, the only thing I am missing at the moment, is the MediaBrowser part, so that I could list my Playlists etc…
I found this in the documentation https://thehomeremote.com/docs/capabilities#media-browser and this https://thehomeremote.com/docs/mediabrowser but I cant seem to figure out how to use this MediaBrowser feature, lets say for example if I have an array of objects, which contain the Title, Image of the playlists, how do I make this visible in the media browser?

Plugins cannot currently use the MediaBrowser capability. That functionality hasn’t been implemented in the plugin architecture yet. Your only option is to use the MediaInputSource which may limit what you are trying to do here. The MediaInputSource capability wasn’t really designed for nested browsing. I suppose each time the user clicks one of your SupportedInputSources you could repopulate SupportedInputSources with a new set of items representing those at the current level. That might work for you.

Happy to see a spotify plugin! There has been quite a few folks looking for this including myself.

I usually kick off spotify from the app but would love to have this for monitoring and skipping tracks from my wall mounted tablets. :clap: :clap: