#!/usr/bin/env pythonfromsocoimportSoCoif__name__=='__main__':sonos=SoCo('192.168.1.102')# Pass in the IP of your Sonos speaker# You could use the discover function instead, if you don't know the IP# Pass in a URI to a media file to have it streamed through the Sonos speakersonos.play_uri('http://archive.org/download/TenD2005-07-16.flac16/TenD2005-07-16t10Wonderboy_64kb.mp3')track=sonos.get_current_track_info()printtrack['title']sonos.pause()# Play a stopped or paused tracksonos.play()

Example Applications

To show off what can be made with SoCo, a simple web application is included in the examples folder.

Screenshot of web app

Features

SoCo supports the following controls amongst others:

Play

Pause

Stop

Next track

Previous track

Get current transport information(if speaker is
playing,paused,stopped)

Get information about the currently playing track

Track title

Artist

Album

Album Art (if available)

Track length

Duration played (for example, 30 seconds into a 3 minute song)

Playlist position (for example, item 5 in the playlist)

Track URI

Mute (or unmute) the speaker

Get or set the speaker volume

Get or set the speaker’s bass EQ

Get or set the speaker’s treble EQ

Toggle the speaker’s loudness compensation

Turn on (or off) the white status light on the unit

Switch the speaker’s source to line-in or TV input (if the Zone Player
supports it)

Get the speaker’s information

Zone Name

Zone Icon

UID (usually something like RINCON_XXXXXXXXXXXXXXXXX)

Serial Number

Software version

Hardware version

MAC Address

Set the speaker’s Zone Name

Find all the Sonos speakers in a network.

Put all Sonos speakers in a network into “party mode”.

“Unjoin” speakers from a group.

Manage the Sonos queue (get the items in it, add to it, clear it,
play a specific song from it)

Get the saved favorite radio stations and shows (title and stream
URI)

Looking for a GUI that’s more than just a sample project? Joel
Björkman is building a Sonos Controller GUI–great for folks on Linux
where there isn’t an official Sonos Controller application! Find, fork,
and contribute to it here: https://github.com/labero/SoCo-Tk.