Crates.io | rusty-sonos |
lib.rs | rusty-sonos |
version | 0.2.5 |
source | src |
created_at | 2023-12-20 03:35:16.815166 |
updated_at | 2024-03-30 19:54:04.258227 |
description | A library for communicating with and discovering Sonos speakers |
homepage | |
repository | https://github.com/Brendon-Hablutzel/rusty-sonos |
max_upload_size | |
id | 1074964 |
size | 36,140 |
A library for discovering and interacting with Sonos speakers, written in Rust.
The primary functionality of this library is to provide a wrapper for speaker discovery and speaker actions.
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()
.
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 trackpause
: pauses playback of the current trackget_current_track
: returns information about the current trackset_current_uri
: sets the current track from a URIget_volume
: returns the current volumeset_volume
: sets the volume to the given valueget_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 queueenter_queue
: enters the queueadd_track_to_queue
: adds a track to the queuemove_to_next_track
: skips to the next trackmove_to_previous_track
: moves to the previous trackclear_queue
: removes all tracks from the queueend_external_control
: ends control of the speaker by external services, such as SpotifyGenerally, the speakers' API is UPnP-based
These unofficial docs were used to build this library. They contain information about various services, endpoints, and responses.