lib/sonos/endpoint/a_v_transport.rb
# Get information about the currently playing track.
# @return [Hash] information about the current track.
Get information about the currently playing track.
Get information about the currently playing track .
def now_playing
    response = send_transport_message('GetPositionInfo')
    body = response.body[:get_position_info_response]
    doc = Nokogiri::XML(body[:track_meta_data])
    return nil if doc.children.length == 0
    art_path = doc.xpath('//upnp:albumArtURI').inner_text
    art_path.sub!('/getaa?s=1=x-sonos-http', '/getaa?s=1&u=x-sonos-http')
    {
      title: doc.xpath('//dc:title').inner_text,
      artist: doc.xpath('//dc:creator').inner_text,
      album: doc.xpath('//upnp:album').inner_text,
      info: doc.xpath('//r:streamContent').inner_text,
      queue_position: body[:track],
      track_duration: body[:track_duration],
      current_position: body[:rel_time],
      uri: body[:track_uri],
      album_art: "http://#{self.ip}:#{Sonos::PORT}#{art_path}"
    }
  end
def now_playing response = send_transport_message ( 'GetPositionInfo' ) body = response . body [ :get_position_info_response ] doc = Nokogiri :: XML ( body [ :track_meta_data ] ) return nil if doc . children . length == 0 art_path = doc . xpath ( '//upnp:albumArtURI' ) . inner_text art_path . sub! ( '/getaa?s=1=x-sonos-http' , '/getaa?s=1&u=x-sonos-http' ) { title : doc . xpath ( '//dc:title' ) . inner_text , artist : doc . xpath ( '//dc:creator' ) . inner_text , album : doc . xpath ( '//upnp:album' ) . inner_text , info : doc . xpath ( '//r:streamContent' ) . inner_text , queue_position : body [ :track ] , track_duration : body [ :track_duration ] , current_position : body [ :rel_time ] , uri : body [ :track_uri ] , album_art : "http://#{self.ip}:#{Sonos::PORT}#{art_path}" } end
Get information about the currently playing track.
Get information about the currently playing track .
# No music # TODO: No idea why this is necessary. Maybe its a Nokogiri thing
information about the current track.
information about the current track .
Hash