Skip to main content

Crate snapcast_client

Crate snapcast_client 

Source
Expand description

Snapcast client library — embeddable synchronized multiroom audio client.

See also: snapcast-server for the server library.

§Example

use snapcast_client::{SnapClient, ClientConfig, ClientEvent, ClientCommand};

let config = ClientConfig::default();
let (mut client, mut events, mut audio_rx) = SnapClient::new(config);
let cmd = client.command_sender();

// React to events in a separate task
tokio::spawn(async move {
    while let Some(event) = events.recv().await {
        match event {
            ClientEvent::VolumeChanged { volume, muted } => {
                println!("Volume: {volume}, muted: {muted}");
            }
            _ => {}
        }
    }
});

// Stop on Ctrl-C
let stop = cmd.clone();
tokio::spawn(async move {
    tokio::signal::ctrl_c().await.ok();
    stop.send(ClientCommand::Stop).await.ok();
});

client.run().await?;

Modules§

config
Client configuration types mirroring the C++ ClientSettings.
connection
Connection layer — TCP, WebSocket, and WSS implementations.
decoder
Audio decoder trait and implementations.
discovery
mDNS/ZeroConf service discovery for finding snapservers.
stream
Time-synchronized PCM audio stream buffer.
time_provider
Server time synchronization.

Structs§

AudioFrame
Interleaved f32 audio frame produced by the client library.
ClientConfig
Configuration for the embeddable client.
CustomMessage
Custom message for application-defined protocol extensions (type 9+).
SampleFormat
Audio sample format: rate, bit depth, and channel count.
SnapClient
The embeddable Snapcast client.

Enums§

ClientCommand
Commands the consumer sends to the client.
ClientEvent
Events emitted by the client to the consumer.

Constants§

DEFAULT_STREAM_PORT
Default TCP port for binary protocol (streaming clients).
PROTOCOL_VERSION
Snapcast binary protocol version.