Playing sound file on a specific Sonos device

Avatar
  • updated

Can someone tell me how to play a specific sound file in the Music Library of my Sonos system on a specific Sonos. I'm trying to use the ChangeStationByUri(stationName, streamingUrl) function but no success yet. The command is being transferred to the Sonos player when I put the link to the file (\\NAS-....) instead of stationName (and leave streamingURL blank) but my Sonos controller tells me "Unable to locate ...". Also tried putting the audio file in my Sonos favorites and calling the favorite in bOS but no luck so far.

Avatar
Fredrik Sandblom

What I know the only way with bOS is to play a URL.

I have solved this with Python script and play for example Spotify list or notifications with a http request from bOS.

Avatar
Rait Lotamõis

I'm having an odd issue. I can play radio stations without any problems using the ChangeStationByUri function. However, when I'm trying to play a wav file from the Internet (http://IP/dir/to/file.wav) using the same function - it's not working. The title changes to the filename, and the playback time jumps between 0 - 3 seconds but no playback is happening.


When trying to play the same file using a custom script and setting the "SetAVTransportURI" to play the file URL, everything works as expected.

Avatar
Tilen Suhadolnik

ChangeStationByUri only works for streaming uris, for now.

Sonos device in bOS will be improved in the next major version release (bOS 5), which will not happen soon.

Any suggestions about Sonos are welcome.

Avatar
Rait Lotamõis

I actually managed to achieve the above using a HttpRequest from within a Program. I just had to compose the POST request myself. 

Avatar
Ricardo Pinto

Hello Rait,


Would you like to share the implementation?


I'm looking forward to compose the HttpRequest, but either it doesn't work, or it restarts the Sonos and clears the playlist. I've tried several examples with the Headers etc, but I can't get it working.


Kind regards

Avatar
Rait Lotamõis

Hello Ricardo,


you can find a sample here 


This is how I'm playing a wav file for instance. Should be the same for streaming as well, all you need to do is make sure your URI starts with rincon-x-mp3radio:// instead of http://


Also, this only sets the new URI, if you want to play it you will need to send a regular Play command afterwards.



Avatar
Ricardo Pinto

Hello Rait,


Thanks for the example!


Meanwhile I was able to find the correct configs for the headers and post command, but I only got to test play and pause commands, so with your example now it's more clear.


So in practice, with this task I set the file to be played, and then I need to set play to start. Got it! Will test it soon.


Thanks!

Avatar
Ricardo Pinto

Rait, it also works with other file locations, like NAS folder for example.


I was able to successfully set an mp3, located in my NAS public folder.


If you need to try, you can use x-file-cifs://


Example: x-file-cifs://ipaddress/public/file.mp3

Avatar
Dieter Kraewinkels

Hello, can you re-post full example ? thank you !

Avatar
Joachim O

Has anyone had success playing (on a sonos) the files stored locally on the bos controller?

On my jigsaw i have som .mp3 files stored. I'm not able to find the correct path. 

Image 2182