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: usize,
property: &str,
) -> Result<(), MpvError>
async fn observe_property( &self, id: usize, property: &str, ) -> Result<(), MpvError>
Mpv::get_event_stream
and Property
for more information.Source§async fn unobserve_property(&self, id: usize) -> Result<(), MpvError>
async fn unobserve_property(&self, id: usize) -> Result<(), MpvError>
Mpv::get_event_stream
and Property
for more information.