A lightweight Java library for discovering and controlling Sonos speakers over UPnP on your local network.
Sonos API discovers speakers via SSDP and communicates with them using UPnP SOAP services. It is designed to be embedded as a small library and integrates with Spring Boot through auto-configuration.
- Discover Sonos devices on the local network
- Playback control (play, pause, stop)
- Volume control (set, get, mute state)
- Track metadata (artist, album, title)
- Spotify track playback
- Zone and group state queries
- Spring Boot auto-configuration
- Java 17+
- Spring Boot 3.2.4 (optional)
Add the dependency:
<dependency>
<groupId>de.sm.sonos</groupId>
<artifactId>sonos-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>The SonosManager is registered as a Spring bean and can be injected:
@Autowired
private SonosManager sonosManager;
public void playSomeMusic() {
SonosDevice livingRoom = sonosManager.getDeviceByName("Living Room");
if (livingRoom != null) {
livingRoom.setVolume(20);
livingRoom.play();
}
}public static void main(String[] args) {
SonosManager sonosManager = new SonosManager();
sonosManager.discoverDevices();
SonosDevice livingRoom = sonosManager.getDeviceByName("Living Room");
if (livingRoom != null) {
TrackInfo currentTrack = livingRoom.getCurrentTrackInfo();
System.out.println("Current track: " + currentTrack);
livingRoom.setVolume(15);
livingRoom.play();
livingRoom.playSpotifyTrack("spotify:track:12345abcde");
}
}mvn compile
mvn packageMIT. See LICENSE.