Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sonos API

A lightweight Java library for discovering and controlling Sonos speakers over UPnP on your local network.

Overview

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.

Features

  • 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

Requirements

  • Java 17+
  • Spring Boot 3.2.4 (optional)

Spring Boot usage

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();
    }
}

Usage without Spring

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");
    }
}

Build

mvn compile
mvn package

License

MIT. See LICENSE.

About

Java Spring Boot API to Sonos Speakers

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages