bluos-api-rs

Crates.iobluos-api-rs
lib.rsbluos-api-rs
version1.1.2
sourcesrc
created_at2022-02-05 04:28:36.45281
updated_at2024-04-29 23:14:41.943223
descriptionBluOS API wrappers for Rust
homepage
repositoryhttps://github.com/coral/bluos-api-rs
max_upload_size
id527264
size71,596
coral (coral)

documentation

README

BluOS API wrappers for Rust

These are ergonomic wrappers around the BluOS semi-documented API. It ships with discovery using mDNS so you do not have to mess with finding out what the IP is for your BluOS device.

Why would you want this in Rust? Doesn't it make more sense to do something like this in Python or Node? Who would ever use this in Rust? GOOD QUESTIONS OFTEN LACKS GOOD ANSWERS

use anyhow::Result;
use bluos_api_rs::{BluOS, Discovery};

#[tokio::main]
async fn main() -> Result<()> {
    // Find the first device in our network
    let device = Discovery::discover_one().await?;

    // Create a new BluOS device from the discovered address
    let bluos = BluOS::new_from_discovered(device)?;

    // Print the status
    let status = bluos.status().await?;
    dbg!(status);

    // List items in the play queue
    let playlist = bluos.queue(None).await?;
    for n in playlist.entries {
        println!("{}", n.title.unwrap_or_default());
    }

    // Resume playback
    bluos.play().await?;
    
    Ok(())
}

If you don't want Discovery & Tokio you can disable the discover feature.

Commit count: 25

cargo fmt