pub struct Mpv {
command_sender: Sender<(MpvIpcCommand, Sender<MpvIpcResponse>)>,
broadcast_channel: Sender<MpvIpcEvent>,
}
Expand description
The main struct for interacting with mpv.
This struct provides the core API for interacting with mpv.
These functions are the building blocks for the higher-level API provided by the MpvExt
trait.
They can also be used directly to interact with mpv in a more flexible way, mostly returning JSON values.
The Mpv
struct can be cloned freely, and shared anywhere.
It only contains a message passing channel to the tokio task that handles the IPC communication with mpv.
Fields§
§command_sender: Sender<(MpvIpcCommand, Sender<MpvIpcResponse>)>
§broadcast_channel: Sender<MpvIpcEvent>
Implementations§
source§impl Mpv
impl Mpv
sourcepub async fn connect(socket_path: &str) -> Result<Mpv, MpvError>
pub async fn connect(socket_path: &str) -> Result<Mpv, MpvError>
Connect to a unix socket, hosted by mpv, at the given path.
This is the inteded way of creating a new Mpv
instance.
sourcepub async fn connect_socket(socket: UnixStream) -> Result<Mpv, MpvError>
pub async fn connect_socket(socket: UnixStream) -> Result<Mpv, MpvError>
Connect to an existing UnixStream
.
This is an alternative to Mpv::connect
, if you already have a UnixStream
available.
Internally, this is used for testing purposes.
sourcepub async fn disconnect(&self) -> Result<(), MpvError>
pub async fn disconnect(&self) -> Result<(), MpvError>
Disconnect from the mpv socket.
Note that this will also kill communication for all other clones of this instance.
It will not kill the mpv process itself - for that you should use MpvCommand::Quit
or run MpvExt::kill
.
sourcepub async fn get_event_stream(
&self,
) -> impl Stream<Item = Result<Event, MpvError>>
pub async fn get_event_stream( &self, ) -> impl Stream<Item = Result<Event, MpvError>>
Create a new stream, providing Event
s from mpv.
This is intended to be used with MpvCommand::Observe
and MpvCommand::Unobserve
(or [MpvExt::observe_property
] and [MpvExt::unobserve_property
] respectively).
sourcepub async fn run_command_raw(
&self,
command: &str,
args: &[&str],
) -> Result<Option<Value>, MpvError>
pub async fn run_command_raw( &self, command: &str, args: &[&str], ) -> Result<Option<Value>, MpvError>
Run a custom command.
This should only be used if the desired command is not implemented
with MpvCommand
.
sourceasync fn run_command_raw_ignore_value(
&self,
command: &str,
args: &[&str],
) -> Result<(), MpvError>
async fn run_command_raw_ignore_value( &self, command: &str, args: &[&str], ) -> Result<(), MpvError>
Helper function to ignore the return value of a command, and only check for errors.
sourcepub async fn run_command(&self, command: MpvCommand) -> Result<(), MpvError>
pub async fn run_command(&self, command: MpvCommand) -> Result<(), MpvError>
§Description
Runs mpv commands. The arguments are passed as a String-Vector reference:
§Input arguments
- command defines the mpv command that should be executed
- args a slice of
&str
’s which define the arguments
§Example
use mpvipc_async::{Mpv, MpvError};
#[tokio::main]
async fn main() -> Result<(), MpvError> {
let mpv = Mpv::connect("/tmp/mpvsocket").await?;
//Run command 'playlist-shuffle' which takes no arguments
mpv.run_command(MpvCommand::PlaylistShuffle).await?;
//Run command 'seek' which in this case takes two arguments
mpv.run_command(MpvCommand::Seek {
seconds: 0f64,
option: SeekOptions::Absolute,
}).await?;
Ok(())
}
sourcepub async fn get_property<T: GetPropertyTypeHandler>(
&self,
property: &str,
) -> Result<Option<T>, MpvError>
pub async fn get_property<T: GetPropertyTypeHandler>( &self, property: &str, ) -> Result<Option<T>, MpvError>
§Description
Retrieves the property value from mpv.
§Supported types
String
bool
HashMap<String, String>
(e.g. for the ‘metadata’ property)Vec<PlaylistEntry>
(for the ‘playlist’ property)usize
f64
§Input arguments
- property defines the mpv property that should be retrieved
§Example
use mpvipc_async::{Mpv, MpvError};
#[tokio::main]
async fn main() -> Result<(), MpvError> {
let mpv = Mpv::connect("/tmp/mpvsocket").await?;
let paused: bool = mpv.get_property("pause").await?;
let title: String = mpv.get_property("media-title").await?;
Ok(())
}
sourcepub async fn get_property_value(
&self,
property: &str,
) -> Result<Option<Value>, MpvError>
pub async fn get_property_value( &self, property: &str, ) -> Result<Option<Value>, MpvError>
§Description
Retrieves the property value from mpv. The result is always of type String, regardless of the type of the value of the mpv property
§Input arguments
- property defines the mpv property that should be retrieved
§Example
use mpvipc_async::{Mpv, MpvError};
#[tokio::main]
async fn main() -> Result<(), MpvError> {
let mpv = Mpv::connect("/tmp/mpvsocket").await?;
let title = mpv.get_property_string("media-title").await?;
Ok(())
}
sourcepub async fn set_property<T>(
&self,
property: &str,
value: T,
) -> Result<(), MpvError>
pub async fn set_property<T>( &self, property: &str, value: T, ) -> Result<(), MpvError>
§Description
Sets the mpv property <property>
to <value>
.
§Supported types
String
bool
f64
usize
§Input arguments
- property defines the mpv property that should be retrieved
- value defines the value of the given mpv property
<property>
§Example
use mpvipc_async::{Mpv, MpvError};
async fn main() -> Result<(), MpvError> {
let mpv = Mpv::connect("/tmp/mpvsocket").await?;
mpv.set_property("pause", true).await?;
Ok(())
}
Trait Implementations§
source§impl MpvExt for Mpv
impl MpvExt for Mpv
source§async fn seek(&self, seconds: f64, option: SeekOptions) -> Result<(), MpvError>
async fn seek(&self, seconds: f64, option: SeekOptions) -> Result<(), MpvError>
source§async fn playlist_remove_id(&self, id: usize) -> Result<(), MpvError>
async fn playlist_remove_id(&self, id: usize) -> Result<(), MpvError>
source§async fn playlist_play_next(&self, id: usize) -> Result<(), MpvError>
async fn playlist_play_next(&self, id: usize) -> Result<(), MpvError>
source§async fn playlist_play_id(&self, id: usize) -> Result<(), MpvError>
async fn playlist_play_id(&self, id: usize) -> Result<(), MpvError>
source§async fn playlist_move_id(&self, from: usize, to: usize) -> Result<(), MpvError>
async fn playlist_move_id(&self, from: usize, to: usize) -> Result<(), MpvError>
source§async fn playlist_add(
&self,
file: &str,
file_type: PlaylistAddTypeOptions,
option: PlaylistAddOptions,
) -> Result<(), MpvError>
async fn playlist_add( &self, file: &str, file_type: PlaylistAddTypeOptions, option: PlaylistAddOptions, ) -> Result<(), MpvError>
source§async fn observe_property(
&self,
id: u64,
property: &str,
) -> Result<(), MpvError>
async fn observe_property( &self, id: u64, property: &str, ) -> Result<(), MpvError>
Mpv::get_event_stream
and Property
for more information.source§async fn unobserve_property(&self, id: u64) -> Result<(), MpvError>
async fn unobserve_property(&self, id: u64) -> Result<(), MpvError>
Mpv::get_event_stream
and Property
for more information.source§async fn kill(&self) -> Result<(), MpvError>
async fn kill(&self) -> Result<(), MpvError>
source§async fn stop(&self) -> Result<(), MpvError>
async fn stop(&self) -> Result<(), MpvError>
source§async fn set_volume(
&self,
input_volume: f64,
option: NumberChangeOptions,
) -> Result<(), MpvError>
async fn set_volume( &self, input_volume: f64, option: NumberChangeOptions, ) -> Result<(), MpvError>
source§async fn set_speed(
&self,
input_speed: f64,
option: NumberChangeOptions,
) -> Result<(), MpvError>
async fn set_speed( &self, input_speed: f64, option: NumberChangeOptions, ) -> Result<(), MpvError>
source§async fn set_playback(&self, option: Switch) -> Result<(), MpvError>
async fn set_playback(&self, option: Switch) -> Result<(), MpvError>
source§async fn set_mute(&self, option: Switch) -> Result<(), MpvError>
async fn set_mute(&self, option: Switch) -> Result<(), MpvError>
source§async fn set_loop_playlist(&self, option: Switch) -> Result<(), MpvError>
async fn set_loop_playlist(&self, option: Switch) -> Result<(), MpvError>
source§async fn set_loop_file(&self, option: Switch) -> Result<(), MpvError>
async fn set_loop_file(&self, option: Switch) -> Result<(), MpvError>
source§async fn get_playlist(&self) -> Result<Playlist, MpvError>
async fn get_playlist(&self) -> Result<Playlist, MpvError>
source§async fn get_metadata(&self) -> Result<HashMap<String, MpvDataType>, MpvError>
async fn get_metadata(&self) -> Result<HashMap<String, MpvDataType>, MpvError>
source§async fn get_time_pos(&self) -> Result<Option<f64>, MpvError>
async fn get_time_pos(&self) -> Result<Option<f64>, MpvError>
source§async fn get_time_remaining(&self) -> Result<Option<f64>, MpvError>
async fn get_time_remaining(&self) -> Result<Option<f64>, MpvError>
source§async fn get_duration(&self) -> Result<f64, MpvError>
async fn get_duration(&self) -> Result<f64, MpvError>
source§async fn get_playlist_pos(&self) -> Result<usize, MpvError>
async fn get_playlist_pos(&self) -> Result<usize, MpvError>
source§async fn is_playing(&self) -> Result<bool, MpvError>
async fn is_playing(&self) -> Result<bool, MpvError>
source§async fn playlist_is_looping(&self) -> Result<LoopProperty, MpvError>
async fn playlist_is_looping(&self) -> Result<LoopProperty, MpvError>
source§async fn file_is_looping(&self) -> Result<LoopProperty, MpvError>
async fn file_is_looping(&self) -> Result<LoopProperty, MpvError>
Auto Trait Implementations§
impl Freeze for Mpv
impl RefUnwindSafe for Mpv
impl Send for Mpv
impl Sync for Mpv
impl Unpin for Mpv
impl UnwindSafe for Mpv
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)