SONOS - Play Radio Station

Forum to ask for any help
Post Reply
robertwo
Posts: 4
Joined: Wed Oct 08, 2014 3:31 pm

SONOS - Play Radio Station

Post by robertwo » Tue Oct 14, 2014 4:07 pm

I'm hoping that someone has already done this and can help me get this working.

I am trying to switch/play a radio station from a single control.

I know what I need to send as a command to do this and then send the Play command directly after, but I just cannot get the formatting correct.

Here's what I have so far:

POST /MediaRenderer/RenderingControl/Control HTTP/1.1\x0D\x0ACONNECTION: close HOST: 192.168.0.27:1400\x0D\x0ACONTENT-LENGTH: 903\x0D\x0ACONTENT-TYPE: text/xml; charset="utf-8"\x0D\x0ASOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"\x0D\x0A\x0D\x0A<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-sonosapi-stream:s86682?sid=254&flags=32</CurrentURI><CurrentURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="F00090020s86682" parentID="F00020000search%3astation:capital" restricted="true"><dc:title>Capital Edinburgh</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>\x0D\x0A

robertwo
Posts: 4
Joined: Wed Oct 08, 2014 3:31 pm

Re: SONOS - Play Radio Station

Post by robertwo » Thu Oct 16, 2014 2:08 pm

I have resolved this and the command I now issue is:

POST /MediaRenderer/AVTransport/Control HTTP/1.1\x0D\x0ACONNECTION: close HOST: 1400\x0D\x0ACONTENT-LENGTH: 390\x0D\x0ACONTENT-TYPE: text/xml; charset="utf-8"\x0D\x0ASOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"\x0D\x0A\x0D\x0A<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encodin ... ansportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-rincon-mp3radio://tx.whatson.com/icecast.php?i=kissnationallow.mp3</CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransport></s:Body></s:Envelope>\x0D\x0A

Need to update the two areas highlighted in bold.

The CONTENT-LENGTH = Total Characters between <s:Envelope & </s:Envelope> (Inclusive of the Tags) Simpy copy the entire string to something like NotePad++ and check the character length.

The string for the Radio Station can be found by:

1. Use Sonos PC App to load the desired Radio Station and set it so its playing
2. Go to http://<IP Address of Sonos Player>:1400/status/radiolog
3. Copy the link to the radio station

Example of result from point 2:

Timestamp Type URI
71595 redir x-rincon-mp3radio://tx.whatson.com/icecast.php?i=kissnationallow.mp3
71595 stream x-rincon-mp3radio://tx.whatson.com/icecast.php?i=kissnationallow.mp3

The problem seemed to be in the <CurrentURIMetaData> Tag. Leaving it blank plays the staion but if you look in the Sonos PC App the playing name of the station is simply the link from point 3 above. Not the biggest problem to be honest.

If I manage to sort out the metadata format correctly I'll post it back here.

robertwo
Posts: 4
Joined: Wed Oct 08, 2014 3:31 pm

Re: SONOS - Play Radio Station

Post by robertwo » Thu Oct 16, 2014 2:16 pm

I forgot to mention you also need to send the PLAY command directly after sending this command.

To do this I setup 2 actions on a button:

1. Send the Radio Station Command
2. Send the PLAY Command after 0.5 Second Delay

If anyone needs them, the basic command for Sonos can be found in the attached file (re-posting someone else's file + a couple of extras).
You do not have the required permissions to view the files attached to this post.

Post Reply