8 releases
0.2.5 | Mar 30, 2024 |
---|---|
0.2.4 | Dec 31, 2023 |
0.1.2 | Dec 20, 2023 |
#7 in #speaker
412 downloads per month
35KB
692 lines
Rusty-Sonos
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 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 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.
Dependencies
~4–16MB
~209K SLoC