Expand description
§nowhear
Cross-platform library for monitoring media playback information.
This library provides a unified API to monitor media players across Linux, macOS, and Windows, allowing you to retrieve current track information and subscribe to playback events.
§Platform Support
- Linux: Uses MPRIS D-Bus interface
- macOS: Uses AppleScript to query Music.app and Spotify
- Windows: Uses Windows Media Control API (
GlobalSystemMediaTransportControlsSessionManager)
§Basic Usage
§Listing Players
use nowhear::{MediaSource, MediaSourceBuilder, Result};
#[tokio::main]
async fn main() -> Result<()> {
let source = MediaSourceBuilder::new().build().await?;
let players = source.list_players().await?;
println!("Available players: {:?}", players);
Ok(())
}§Getting Player Information
use nowhear::{MediaSource, MediaSourceBuilder, Result};
#[tokio::main]
async fn main() -> Result<()> {
let source = MediaSourceBuilder::new().build().await?;
let player_info = source.get_player("spotify").await?;
if let Some(track) = player_info.current_track {
println!("Now playing: {} by {}", track.title, track.artist.join(", "));
}
Ok(())
}§Subscribing to Events
use nowhear::{MediaSource, MediaSourceBuilder, Result};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<()> {
let source = MediaSourceBuilder::new().build().await?;
let mut stream = source.event_stream().await?;
while let Some(event) = stream.next().await {
println!("Event: {:?}", event);
}
Ok(())
}Re-exports§
pub use error::MediaSourceError;pub use error::Result;pub use source::MediaSource;pub use source::MediaSourceBuilder;pub use types::MediaEvent;pub use types::PlaybackState;pub use types::PlayerInfo;pub use types::Track;