bencevans / node-sonos

🔈 Sonos Media Player Interface/Client
https://www.npmjs.com/package/sonos
MIT License
702 stars 147 forks source link

Playing a Spotify track by URN renders currentTrack data unusable #445

Closed fabdrol closed 4 years ago

fabdrol commented 4 years ago

When I attempt to play a track using a spotify track URN (e.g. spotify:track:6sYJuVcEu4gFHmeTLdHzRz?sid=9&flags=8224&sn=1), all currentTrack data disappears. The track URN is shown in the title instead.

Expected Behavior

I'd expect the currentTrack data to be updated according to the new playing track

Current Behavior

No track meta data is visible in currentTrack. The URN is set as the title instead.

Sample code or executed example

await sonos.play(spotify:track:6sYJuVcEu4gFHmeTLdHzRz?sid=9&flags=8224&sn=1)
const currentTrack = await sonos.currentTrack()
console.log(currentTrack)

Versions (and Environment)

Node version: 8.12.0 node-sonos version: ^1.12.4 OS: MacOS

bencevans commented 4 years ago

:tada: This issue has been resolved in version 1.12.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

svrooij commented 4 years ago

If you specify the spotify track without the query string, it just works. I also changed the sample (with your song!!)

kimaldis commented 2 years ago

I'm still having trouble with this. Calling device.play( uri ) results in subsequent calls to device.currentTrack() returns the below. I've tried removing the querystring also but that just plays the first track in the album.

All thoughts welcome, thanks

{
  id: null,
  parentID: null,
  title: null,
  artist: null,
  album: null,
  albumArtist: null,
  albumArtURI: null,
  uri: 'x-sonos-spotify:spotify%3atrack%3a3Fa3zWAeTGC1urAGjZxDX7?sid=9&flags=8224&sn=1',
  duration: 0,
  queuePosition: 12
}
svrooij commented 2 years ago

Albums have to be added to the queue.

For the rest, just remove the query string and you should be good to go.

kimaldis commented 2 years ago

The album is in the queue; I'm getting the uri from a track that's in the return from device.getQueue().

kimaldis commented 2 years ago

By way of clarification, with an album queued and playing:

import { Sonos } from 'sonos'

const device = new Sonos( ipAddressOfDevice );

device.getQueue() .then( queue => {

    // console.log( "Queue", queue )

    const firstTrack = queue.items[0];

    // console.log( "Track", firstTrack )

    device.currentTrack().then( currentTrack => {
        console.log( "CurrentTrack Before device.play()", currentTrack )

        device.play( firstTrack.uri ).then( () => {
            device.currentTrack().then( currentTrack => {
                console.log( "CurrentTrack after device.play", currentTrack )
            })
        })
    })

})

Gives the following output:

CurrentTrack Before device.play() {
  id: null,
  parentID: null,
  title: 'Spirit Power and Soul',
  artist: 'Johnny Marr',
  album: 'Fever Dreams Pts 1 - 4',
  albumArtist: null,
  albumArtURI: '/getaa?s=1&u=x-sonos-spotify%3aspotify%253atrack%253a6OivYrVu0KrssrUuy3GUr6%3fsid%3d9%26flags%3d8224%26sn%3d1',
  position: 11,
  duration: 278,
  albumArtURL: 'http://192.168.1.68:1400/getaa?s=1&u=x-sonos-spotify%3aspotify%253atrack%253a6OivYrVu0KrssrUuy3GUr6%3fsid%3d9%26flags%3d8224%26sn%3d1',
  uri: 'x-sonos-spotify:spotify%3atrack%3a6OivYrVu0KrssrUuy3GUr6?sid=9&flags=8224&sn=1',
  queuePosition: 1
}
13:21:28.515 CurrentTrack after device.play {
  id: null,
  parentID: null,
  title: null,
  artist: null,
  album: null,
  albumArtist: null,
  albumArtURI: null,
  position: 0,
  duration: 0,
  albumArtURL: null,
  uri: 'x-sonos-spotify:spotify%3atrack%3a6OivYrVu0KrssrUuy3GUr6?sid=9&flags=8224&sn=1',
  queuePosition: 17
}
svrooij commented 2 years ago

The trach uri that you get back is from the speaker. Those cannot yet be used to start playback.

Some urls are mapped to guess the required metadata.

https://github.com/bencevans/node-sonos/blob/7d6eaaa2ca35685abe2a7792e3e4f5b8dfc4707c/lib/helpers.js#L131

You'll see sonos:track:... mapped here for instance.

kimaldis commented 2 years ago

got it. Many thanks.