| Crates.io | moosicbox_audio_zone |
| lib.rs | moosicbox_audio_zone |
| version | 0.1.4 |
| created_at | 2024-10-04 16:47:30.930581+00 |
| updated_at | 2025-07-21 19:29:44.161296+00 |
| description | MoosicBox audio zone package |
| homepage | |
| repository | https://github.com/MoosicBox/MoosicBox |
| max_upload_size | |
| id | 1396788 |
| size | 79,797 |
Basic audio zone database management for MoosicBox applications.
The MoosicBox Audio Zone package provides:
api feature)events feature)git clone https://github.com/MoosicBox/MoosicBox.git
cd MoosicBox
cargo build --release --package moosicbox_audio_zone
[dependencies]
moosicbox_audio_zone = { path = "../audio_zone" }
# Optional: Enable API endpoints
moosicbox_audio_zone = {
path = "../audio_zone",
features = ["api"]
}
# Optional: Enable event system
moosicbox_audio_zone = {
path = "../audio_zone",
features = ["events"]
}
use moosicbox_audio_zone::{zones, get_zone, create_audio_zone, CreateAudioZone};
use switchy_database::config::ConfigDatabase;
async fn manage_zones(db: &ConfigDatabase) -> Result<(), Box<dyn std::error::Error>> {
// Get all zones
let all_zones = zones(db).await?;
println!("Found {} zones", all_zones.len());
// Get specific zone
if let Some(zone) = get_zone(db, 1).await? {
println!("Zone: {} (ID: {})", zone.name, zone.id);
}
// Create new zone
let new_zone = CreateAudioZone {
name: "Living Room".to_string(),
// ... other zone configuration
};
let created = create_audio_zone(db, &new_zone).await?;
println!("Created zone: {}", created.name);
Ok(())
}
use moosicbox_audio_zone::{update_audio_zone, delete_audio_zone, UpdateAudioZone};
async fn modify_zones(db: &ConfigDatabase) -> Result<(), Box<dyn std::error::Error>> {
// Update zone
let update = UpdateAudioZone {
id: 1,
name: Some("Updated Living Room".to_string()),
// ... other fields to update
};
let updated = update_audio_zone(db, update).await?;
println!("Updated zone: {}", updated.name);
// Delete zone
if let Some(deleted) = delete_audio_zone(db, 1).await? {
println!("Deleted zone: {}", deleted.name);
}
Ok(())
}
use moosicbox_audio_zone::zones_with_sessions;
use switchy_database::{config::ConfigDatabase, profiles::LibraryDatabase};
async fn get_zones_with_sessions(
config_db: &ConfigDatabase,
library_db: &LibraryDatabase,
) -> Result<(), Box<dyn std::error::Error>> {
let zones = zones_with_sessions(config_db, library_db).await?;
for zone in zones {
println!("Zone: {} - Session: {:?}", zone.name, zone.session);
}
Ok(())
}
// Core zone operations
pub async fn zones(db: &ConfigDatabase) -> Result<Vec<AudioZone>, DatabaseFetchError>;
pub async fn get_zone(db: &ConfigDatabase, id: u64) -> Result<Option<AudioZone>, DatabaseFetchError>;
pub async fn create_audio_zone(db: &ConfigDatabase, zone: &CreateAudioZone) -> Result<AudioZone, DatabaseFetchError>;
pub async fn update_audio_zone(db: &ConfigDatabase, update: UpdateAudioZone) -> Result<AudioZone, DatabaseFetchError>;
pub async fn delete_audio_zone(db: &ConfigDatabase, id: u64) -> Result<Option<AudioZone>, DatabaseFetchError>;
// Session integration
pub async fn zones_with_sessions(
config_db: &ConfigDatabase,
library_db: &LibraryDatabase,
) -> Result<Vec<AudioZoneWithSession>, DatabaseFetchError>;
The package uses models from moosicbox_audio_zone_models:
api: Enable REST API endpoints for zone managementevents: Enable event system for zone configuration changesmoosicbox_audio_zone_models for data structuresAll operations return Result types with appropriate error handling:
When the api feature is enabled, REST endpoints are available for zone management through the web interface.
When the events feature is enabled, zone configuration changes trigger events that can be consumed by other parts of the MoosicBox system.