Giter VIP home page Giter VIP logo

sonos-api-java's Introduction

Sonos API client for Java

This library provides a simple integration with the Sonos API, allowing you to control players and content from any Java app.

Please note that this library is currently still in development. Some aspects (particularly with the SMAPI) cannot be tested due to a lack of access, others due to not owning devices with specific features.

Build Status

Prerequisites

Before using the library, it's recommended that you read the official documentation published on the Sonos Developer site. The reference documentation is also detailed and provides a good overview of the many different resources and endpoints open to you.

You'll need to register with Sonos, create a Control Integration, and finally generate client credentials to be able to connect with the Sonos API. It's also recommended that you have at least one Sonos device to be able to properly test and play with your application (plus, listening to music or watching movies with Sonos is awesome anyway!)

Maven Setup

<dependency>
  <groupId>engineer.nightowl</groupId>
  <artifactId>sonos-api-java</artifactId>
  <version><LATEST-VERSION></version>
</dependency>

Getting Started

Create a new configuration object, set your integration's properties (see further above on how to obtain these), then create a client and pass in that configuration:

final SonosApiConfiguration configuration = new SonosApiConfiguration();
configuration.setApiKey(properties.getProperty("apiKey"));
configuration.setApiSecret(properties.getProperty("apiSecret"));
configuration.setApplicationId(properties.getProperty("applicationId"));

final SonosApiClient client = new SonosApiClient(configuration);

Then use the client to view and modify the user's devices - the following types of resource are available:

  • audioClip
  • authorize
  • favorite
  • group
  • groupVolume
  • homeTheater
  • household
  • musicServiceAccounts
  • playbackMetadata
  • playback
  • playbackSession
  • playerVolume
  • playlist
  • settings

For example, to set all 'groups' (aka rooms) to use crossfade when music is playing, you could run the following:

final SonosGroups groups = client.group().getGroups("authToken", "householdId");
final SonosPlayMode playMode = new SonosPlayMode();
playMode.setCrossfade(true);

for (final SonosGroup group : groups.getGroups())
{
    client.playback().setPlayModes("authToken", group.getId(), playMode);
}

sonos-api-java's People

Contributors

dependabot[bot] avatar nicman42 avatar nightowlengineer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

eeriksen nicman42

sonos-api-java's Issues

Wrong Namespace

Describe what's going wrong
Just found a wrong namespace

Exception in thread "main" SonosGlobalError{errorCode=ERROR_UNSUPPORTED_NAMESPACE, reason='Namespace not found'}
at engineer.nightowl.sonos.api.resource.GroupResource.modifyGroupMembers(GroupResource.java:105)

String.format("/v1/groups/%s/modifyGroupMembers", groupId)
must be
String.format("/v1/groups/%s/groups/modifyGroupMembers", groupId)

same with setGroupMembers

described in https://developer.sonos.com/reference/control-api/groups/modifygroupmembers/

Environment:

  • sonos-api-java version: [e.g. 0.0.22]
  • Sonos API version: [e.g. v1]

Document configuration class more thoroughly

Describe what's going wrong
Couln't use the library: "Invalid token". Please describe what the sonos applicationId is. Do we need other settings e.g. event callback url or something else?

Log

15:25:09.713 INFO  [main] e.nightowl.sonos.api.SonosApiClient - Initialising sonos-api-java:0.0.9
15:25:09.717 DEBUG [main] e.nightowl.sonos.api.SonosApiClient - Using default HttpClient
15:25:10.161 DEBUG [main] e.n.sonos.api.resource.GroupResource - Sending request to https://api.ws.sonos.com/control/api/v1/households/householdId/groups
Exception in thread "main" engineer.nightowl.sonos.api.exception.SonosApiClientException: Invalid token
	at engineer.nightowl.sonos.api.resource.BaseResource.callApi(BaseResource.java:81)
	at engineer.nightowl.sonos.api.resource.BaseResource.getFromApi(BaseResource.java:178)
	at engineer.nightowl.sonos.api.resource.GroupResource.getGroups(GroupResource.java:51)
	at SonosTest.main(SonosTest.java:21)

Question: Is easy discover of devices still possible?

Sorry for this question type of issue, but I'm currently looking at which Java library to use for a Sonos project I'm planning. Compared to this (a bit dated) library, whose basic usage is to simply run List<SonosDevice> devices = SonosDiscovery.discover();, the prerequisites for this library seem rather complex. Is this due to Sonos having changed something on their side (and that dated library would not work anymore), or is it due to this library doing something different than the other library, or is it due to something else?

Thanks for any insights!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.