rusty-sonos

Crates.iorusty-sonos
lib.rsrusty-sonos
version0.2.5
sourcesrc
created_at2023-12-20 03:35:16.815166
updated_at2024-03-30 19:54:04.258227
descriptionA library for communicating with and discovering Sonos speakers
homepage
repositoryhttps://github.com/Brendon-Hablutzel/rusty-sonos
max_upload_size
id1074964
size36,140
Brendon Hablutzel (Brendon-Hablutzel)

documentation

README

Rusty-Sonos

crates.io Documentation MIT licensed

A library for discovering and interacting with Sonos speakers, written in Rust.

Features

The primary functionality of this library is to provide a wrapper for speaker discovery and speaker actions.

Discovery

To discover all speakers on the current network, use discover_devices(). This will return basic information about speakers (including IP addresses) about any speakers that were found. Internally, this uses the SSDP protocol.

To get information about a specific speaker, given its IP, use get_speaker_info().

Speaker Interaction

Interaction with speakers is done through a single struct, Speaker, which has methods for all the features that are currently implemented. To use Speaker, you must know the speaker's IP address (refer to the discovery section for how to find this):

use rusty_sonos::speaker::Speaker;
use std::net::Ipv4Addr;

let ip_addr = Ipv4Addr::from_str("192.168.1.0").unwrap();

let speaker = Speaker::new(ip_addr).await.unwrap();

speaker.play().await.unwrap(); // plays the current track

A non-exhaustive list and description of speaker methods is provided below:

  • play: starts or resumes playback of the current track
  • pause: pauses playback of the current track
  • get_current_track: returns information about the current track
  • set_current_uri: sets the current track from a URI
  • get_volume: returns the current volume
  • set_volume: sets the volume to the given value
  • get_playback_status: gets the playback status (playing, paused, etc.)
  • seek: starts playback from the provided time in the track (hh:mm:ss)
  • get_queue: returns the tracks currently in the queue
  • enter_queue: enters the queue
  • add_track_to_queue: adds a track to the queue
  • move_to_next_track: skips to the next track
  • move_to_previous_track: moves to the previous track
  • clear_queue: removes all tracks from the queue
  • end_external_control: ends control of the speaker by external services, such as Spotify

Notes

Generally, the speakers' API is UPnP-based

These unofficial docs were used to build this library. They contain information about various services, endpoints, and responses.

Commit count: 23

cargo fmt