pub trait MediaSource: Send + Sync {
// Required methods
fn list_players(&self) -> impl Future<Output = Result<Vec<String>>> + Send;
fn get_player(
&self,
player_name: &str,
) -> impl Future<Output = Result<PlayerInfo>> + Send;
fn event_stream(&self) -> impl Future<Output = Result<EventStream>> + Send;
}Expand description
Main trait for media source functionality.
This trait provides methods to list players, query player information, and subscribe to media events. It is implemented by platform-specific media sources.
Required Methods§
Sourcefn get_player(
&self,
player_name: &str,
) -> impl Future<Output = Result<PlayerInfo>> + Send
fn get_player( &self, player_name: &str, ) -> impl Future<Output = Result<PlayerInfo>> + Send
Gets detailed information about a specific player.
§Arguments
player_name- The name of the player to query
§Returns
Returns PlayerInfo containing the current track, playback state, and other details.
§Errors
Returns MediaSourceError::PlayerNotFound if the player is not running.
§Examples
let source = MediaSourceBuilder::new().build().await?;
let player_info = source.get_player("spotify").await?;
println!("Current track: {:?}", player_info.current_track);Sourcefn event_stream(&self) -> impl Future<Output = Result<EventStream>> + Send
fn event_stream(&self) -> impl Future<Output = Result<EventStream>> + Send
Creates an event stream that emits media events.
The stream yields events such as track changes, playback state changes, and player additions/removals. The stream continues indefinitely until dropped.
§Returns
Returns a stream that yields MediaEvent items.
§Examples
let source = MediaSourceBuilder::new().build().await?;
let mut stream = source.event_stream().await?;
while let Some(event) = stream.next().await {
println!("Event: {:?}", event);
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.