简体   繁体   中英

How to scan for SONOS speaker on same WiFi network?

I am trying to develop iOS intercom app for the SONOS speaker (to broadcast the audio from the app) for which I need to scan the devices on the same network, I tried to research lot of articles but no luck in finding the right direction. I have noticed there are multiple apps on the App store doing that. For ex: IntercomWiFi , Voice intercom for Sonos , Intercom for Sonos .

Edited:

I have researched SONOS developer doc which doesn't provide a solution to directly communicate with SONOS device and broadcast the local audio to the app, though there are Apps out there in the app store doing that.

Sonos devices can be found on the local subnet with an SSDP search.

Just so you know, while playing audio to a Sonos device is pretty trivial, resuming what was previously playing on a device is very, very difficult, and in many cases impossible.

Each sonos speaker has a local UPNP api that can be used to control the music.

First you need to find the speakers, by using SSDP. sonos-device-discovery . This shows how to do it in Node/Typescript, you should do the same in Swift.

For hosting the music file you have several options:

  • Upload the file to some cloud hosting and play it from there
  • Start a http server on the phone (not sure if that is possible on iOS) and host the file on the phone.

You should now have the IP of the sonos speaker and the url of the MP3, then it's just a matter of sending the following soap command:

POST /MediaRenderer/AVTransport/Control
Host: 192.168.0.1:1400
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"
Content-type: text/xml; charset=utf8

And the following body:

<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>http://your.url.here/file.mp3</CurrentURI>
  <CurrentURIMetaData></CurrentURIMetaData>
</u:SetAVTransportURI>
</s:Body>
</s:Envelope>

However it isn't very hard to play a single file, it is however pretty hard to revert everything back to normal after your song has played. this code accomplishes that in node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM