Logic Machine Forum
sonos play/queue playlist - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: sonos play/queue playlist (/showthread.php?tid=144)

Pages: 1 2 3


RE: sonos play/queue playlist - Erwin van der Zwart - 09.03.2016

Hi Ruben,

Adjust group address and image size in the parameter section and run this script once, it creates a albumart.html file in the image folder.

Create a image frame in your visu and use this as url:  /scada/resources/img/albumart.html

This should give you the Sonos albumart image for local sources

BR,

Erwin


RE: sonos play/queue playlist - zoltan - 06.09.2016

(05.03.2016, 13:01)Erwin van der Zwart Wrote: Try this script, the explanation is added into the script. Its still in development and the only thing i need to add is getting albumart URI for streaming content.

Hello Erwin,

I'm getting errors like this,when adjusting volume:
Code:
Line 463: attempt to call field 'tonumber' (a nil value)
Line 485: attempt to call field 'tonumber' (a nil value)
Seems that the volume variable is somehow cleared after FOR loop.

The volume feedback is correct. Start/stop is working, prev/next didn't tried yet.

Using the latest RC firmware (20160714). Copy/paste attempted with chrome, firefox, file download - then open with notepad, notepad++, same behaviour.


RE: sonos play/queue playlist - admin - 06.09.2016

Replace lmcore.tonumber with tonumber everywhere and it should work. This function has been removed in RC firmware.


RE: sonos play/queue playlist - zoltan - 06.09.2016

Thanks,
I'll try it tomorrow.


RE: sonos play/queue playlist - FatMax - 18.09.2016

Just a little hijack;

When removing lmcore in a different script, the function inttohex and hextoint is not recognised. Gives me errors. Can´t find a reference to these functions anywhere. Could you elaborate further?


RE: sonos play/queue playlist - Erwin van der Zwart - 18.09.2016

Hi,

You only need to remove it on the tonumber as the command
is a default LUA command, inttohex is a custom command so
there lmcore. is needed.

To see a list of commands you can use press CTRL+space in
the script editor.

BR,

Erwin


RE: sonos play/queue playlist - josep - 21.09.2016

Hello, I'm trying it into a HomeLynk and works all fine within AlbumArt. The Album Art scrip creates a html image but all the time it appears like a NO ALBUM ART image, I can meke something to arrange this? Thank you veruy much.


RE: sonos play/queue playlist - Erwin van der Zwart - 21.09.2016

Hi Josep,

Can you give some more details?

What FW do you run?

What script version do you use to read the Sonos?

Is there a (valid) albumart URL visable  on the object that is set inside the Albumart.html file?

BR,

Erwin


RE: sonos play/queue playlist - josep - 23.09.2016

Hello Erwin,

The Homelynk is a 1.5.1 version.

The Script that I use is the Script that you upload to trhis forum post, the version is 1.1

The URL album art that I can see inside 1/1/18 adress is this, for example:
example 1 (tunein Radio) :x-rincon-mp3radio://streaming3.radiocat.net/
example 2 (Apple Music Album) /getaa?s=1&u=x-sonos-http%3asong%253a639380945.mp4%3fsid%3d204%26flags%3d8224%26sn%3d1

THX

Josep


RE: sonos play/queue playlist - Erwin van der Zwart - 23.09.2016

Hi Josep,

I think this version does not support streaming album art, as i already wrote in the post 09-03-2016:

Albumart URL should work now with local content, i'm still searching for a good solution for streaming content album art, but that's a hard one to tackle, when i solved it i let you know.

We created a app for Sonos that is still in development (we have it running on several sites for beta testing), in this app i solved the issue (puzzle) with streaming art.

Or you wait for the app or i must prepare a new version script for you..
 
BR,

Erwin


RE: sonos play/queue playlist - josep - 23.09.2016

Hello Erwin,

This app that you prepare it working in HomeLynk or only in LogicMachine? Can I try the beta version?

Thankyou very much.


RE: sonos play/queue playlist - Erwin van der Zwart - 23.09.2016

Hi Josep,

Look at my avatar (: 

I'ts designed on a homeLYnk, but i see no reason why it doesn't work on a LM.

I'm still fixing a few found items, when done i let you know.

BR,

Erwin van der Zwart


RE: sonos play/queue playlist - josep - 23.09.2016

Big Grin

Thank you very much!

(P.D. some news about Homekit in Homelynk? I'm trying Thinka and it works fine)


RE: sonos play/queue playlist - zoltan - 23.09.2016

+1 for beta testing Wink


RE: sonos play/queue playlist - lenze90 - 24.02.2019

(24.11.2015, 12:23)gjniewenhuijse Wrote:
(23.11.2015, 12:49)admin Wrote: We don't have any Sonos devices so what we can help with is limited.

You can use Node.js library with debug enabled to monitor which kind of requests are being sent and then implement the same thing in LM.

Some hints for your case:
- To find your playlist id (SQ:1 or similar), you need to get a list of all playlists and find it there
- Use RemoveAllTracksFromQueue to empty current queue
- Use SetPlayMode to set repeat / shuffle
- You don't have to add tracks one by one, you can load the whole playlist (stored queue) in one call

Yes.. it works.
I attached a little bit changed upnpavcmd function.

And two new functions:

Code:
-- find all playlist
function getPlaylists(ip, port)
cBrowse = '<ObjectID>SQ:</ObjectID>' ..
        '<BrowseFlag>BrowseDirectChildren</BrowseFlag>' ..
        '<Filter>*</Filter>' ..
        '<StartingIndex>0</StartingIndex>' ..
        '<RequestedCount>25</RequestedCount>' ..
        '<SortCriteria>*</SortCriteria>'
  res,err = upnpavcmd(ip, port, 'Browse', cBrowse)
  return res,err
end

-- add saved queue (playlist) to queue
function qPlaylist(pId)
uriprm = '<EnqueuedURI>file:///jffs/settings/savedqueues.rsq#'..pId..'</EnqueuedURI>' ..
'<EnqueuedURIMetaData></EnqueuedURIMetaData>' ..
'<DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued>' ..
'<EnqueueAsNext>1</EnqueueAsNext>'
  return uriprm
end

-- find all playlist (run once and note playlist id)
res,err = getPlaylists(ip, 1400)
log(res)

And then you can use:


Code:
-- clear current queue
upnpavcmd(ip, 1400, 'RemoveAllTracksFromQueue')

-- add playlist to queue
upnpavcmd(ip, 1400, 'AddURIToQueue', qPlaylist(2)) -- add the playlist id here

-- play
uri_queue = "x-rincon-queue:RINCON_B8E937A06A3E01400#0" -- add the right URI for the queue
upnpavcmd(ip, 1400, 'SetAVTransportURI', '<CurrentURI>'..uri_queue..'</CurrentURI><CurrentURIMetaData/>')
upnpavcmd(ip, 1400, 'Play', '<Speed>1</Speed>')

Hi Guy, 

how can i find the right URI? 
uri_queue = "x-rincon-queue:RINCON_<my macadress?>" -- add the right URI for the queue


RE: sonos play/queue playlist - lenze90 - 10.03.2019

(24.11.2015, 12:23)gjniewenhuijse Wrote:
(23.11.2015, 12:49)admin Wrote: We don't have any Sonos devices so what we can help with is limited.

You can use Node.js library with debug enabled to monitor which kind of requests are being sent and then implement the same thing in LM.

Some hints for your case:
- To find your playlist id (SQ:1 or similar), you need to get a list of all playlists and find it there
- Use RemoveAllTracksFromQueue to empty current queue
- Use SetPlayMode to set repeat / shuffle
- You don't have to add tracks one by one, you can load the whole playlist (stored queue) in one call

Yes.. it works.
I attached a little bit changed upnpavcmd function.

And two new functions:

Code:
-- find all playlist
function getPlaylists(ip, port)
cBrowse = '<ObjectID>SQ:</ObjectID>' ..
        '<BrowseFlag>BrowseDirectChildren</BrowseFlag>' ..
        '<Filter>*</Filter>' ..
        '<StartingIndex>0</StartingIndex>' ..
        '<RequestedCount>25</RequestedCount>' ..
        '<SortCriteria>*</SortCriteria>'
  res,err = upnpavcmd(ip, port, 'Browse', cBrowse)
  return res,err
end

-- add saved queue (playlist) to queue
function qPlaylist(pId)
uriprm = '<EnqueuedURI>file:///jffs/settings/savedqueues.rsq#'..pId..'</EnqueuedURI>' ..
'<EnqueuedURIMetaData></EnqueuedURIMetaData>' ..
'<DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued>' ..
'<EnqueueAsNext>1</EnqueueAsNext>'
  return uriprm
end

-- find all playlist (run once and note playlist id)
res,err = getPlaylists(ip, 1400)
log(res)

And then you can use:


Code:
-- clear current queue
upnpavcmd(ip, 1400, 'RemoveAllTracksFromQueue')

-- add playlist to queue
upnpavcmd(ip, 1400, 'AddURIToQueue', qPlaylist(2)) -- add the playlist id here

-- play
uri_queue = "x-rincon-queue:RINCON_B8E937A06A3E01400#0" -- add the right URI for the queue
upnpavcmd(ip, 1400, 'SetAVTransportURI', '<CurrentURI>'..uri_queue..'</CurrentURI><CurrentURIMetaData/>')
upnpavcmd(ip, 1400, 'Play', '<Speed>1</Speed>')

Hi,

one question. Unfortunately I get an error message at the function: getPlaylists()

Error message:

Code:
string: HTTP/1.1 500 Internal Server Error
CONTENT-LENGTH: 347
CONTENT-TYPE: text/xml; charset="utf-8"
EXT:
Server: Linux UPnP/1.0 Sonos/48.2-61220 (ZPS14)
Connection: close

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>401</errorCode></UPnPError></detail></s:Fault></s:Body></s:Envelope>


and when I execute the command with various IDs and look in the app to see which playlist the ID could be, the playlists are somehow mixed, although I of course take them all out of the queue first. 

-- add playlist to queue
upnpavcmd(ip, 1400, 'AddURIToQueue', qPlaylist(2)) -- 
I can control unique playlists. I don't understand the problem.


RE: sonos play/queue playlist - admin - 11.03.2019

Have you tried the Sonos app from LM app store? This code is outdated and might not work with newer Sonos devices/firmwares.


RE: sonos play/queue playlist - lenze90 - 11.03.2019

Thanks for your reply. What do you mean, have you try the sonos app from LM appstore?? I installed it, yes. But how do I get the corresponding playlists?

That's a pity when code expires.
Then I can never implement and sell the LM for customers?


RE: sonos play/queue playlist - admin - 12.03.2019

The error that you are getting for getPlaylists can be caused by using old upnpavcmd function. Try using the code attached to this post: https://forum.logicmachine.net/showthread.php?tid=144&pid=601#pid601

As for outdated code I was referring to Sonos UPnP support which can change from version to version. Changes that break backward compatibility in LM happen rarely.


RE: sonos play/queue playlist - lenze90 - 14.03.2019

(09.03.2016, 07:03)Erwin van der Zwart Wrote: Hi Ruben,

Sounds good, I would make que random to avoid listen to same music over and over (:

What commands from the original sonos script are missing in my version? I can add them..

BR,

Erwin

thanks for help admin. But now i get the following error message. :-(

Code:
* string: HTTP/1.1 500 Internal Server Error
Server: Linux UPnP/1.0 Sonos/48.2-61220 (ZPS12)
Connection: close