mpvipc_async::core_api

Struct Mpv

source
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

source

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.

source

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.

source

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.

source

pub async fn get_event_stream( &self, ) -> impl Stream<Item = Result<Event, MpvError>>

Create a new stream, providing Events from mpv.

This is intended to be used with MpvCommand::Observe and MpvCommand::Unobserve (or [MpvExt::observe_property] and [MpvExt::unobserve_property] respectively).

source

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.

source

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.

source

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(())
}
source

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(())
}
source

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(())
}
source

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 Clone for Mpv

source§

fn clone(&self) -> Mpv

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Mpv

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl MpvExt for Mpv

source§

async fn seek(&self, seconds: f64, option: SeekOptions) -> Result<(), MpvError>

Seek to a specific position in the current video.
source§

async fn playlist_shuffle(&self) -> Result<(), MpvError>

Shuffle the current playlist.
source§

async fn playlist_remove_id(&self, id: usize) -> Result<(), MpvError>

Remove an entry from the playlist.
source§

async fn playlist_play_next(&self, id: usize) -> Result<(), MpvError>

Play the next entry in the playlist.
source§

async fn playlist_play_id(&self, id: usize) -> Result<(), MpvError>

Play a specific entry in the playlist.
source§

async fn playlist_move_id(&self, from: usize, to: usize) -> Result<(), MpvError>

Move an entry in the playlist. Read more
source§

async fn playlist_clear(&self) -> Result<(), MpvError>

Remove all entries from the playlist.
source§

async fn playlist_add( &self, file: &str, file_type: PlaylistAddTypeOptions, option: PlaylistAddOptions, ) -> Result<(), MpvError>

Add a file or playlist to the playlist.
source§

async fn restart(&self) -> Result<(), MpvError>

Start the current video from the beginning.
source§

async fn prev(&self) -> Result<(), MpvError>

Play the previous entry in the playlist.
source§

async fn observe_property( &self, id: u64, property: &str, ) -> Result<(), MpvError>

Notify mpv to send events whenever a property changes. See Mpv::get_event_stream and Property for more information.
source§

async fn unobserve_property(&self, id: u64) -> Result<(), MpvError>

Stop observing a property. See Mpv::get_event_stream and Property for more information.
source§

async fn next(&self) -> Result<(), MpvError>

Skip to the next entry in the playlist.
source§

async fn kill(&self) -> Result<(), MpvError>

Stop mpv completely, and kill the process. Read more
source§

async fn stop(&self) -> Result<(), MpvError>

Stop the player completely (as opposed to pausing), removing the pointer to the current video.
source§

async fn set_volume( &self, input_volume: f64, option: NumberChangeOptions, ) -> Result<(), MpvError>

Set the volume of the player.
source§

async fn set_speed( &self, input_speed: f64, option: NumberChangeOptions, ) -> Result<(), MpvError>

Set the playback speed of the player.
source§

async fn set_playback(&self, option: Switch) -> Result<(), MpvError>

Toggle/set the pause state of the player.
source§

async fn set_mute(&self, option: Switch) -> Result<(), MpvError>

Toggle/set the mute state of the player.
source§

async fn set_loop_playlist(&self, option: Switch) -> Result<(), MpvError>

Toggle/set whether the player should loop the current playlist.
source§

async fn set_loop_file(&self, option: Switch) -> Result<(), MpvError>

Toggle/set whether the player should loop the current video.
source§

async fn get_playlist(&self) -> Result<Playlist, MpvError>

Get a list of all entries in the playlist.
source§

async fn get_metadata(&self) -> Result<HashMap<String, MpvDataType>, MpvError>

Get metadata about the current video.
source§

async fn get_file_path(&self) -> Result<String, MpvError>

Get the path of the current video.
source§

async fn get_volume(&self) -> Result<f64, MpvError>

Get the current volume of the player.
source§

async fn get_speed(&self) -> Result<f64, MpvError>

Get the playback speed of the player.
source§

async fn get_time_pos(&self) -> Result<Option<f64>, MpvError>

Get the current position in the current video.
source§

async fn get_time_remaining(&self) -> Result<Option<f64>, MpvError>

Get the amount of time remaining in the current video.
source§

async fn get_duration(&self) -> Result<f64, MpvError>

Get the total duration of the current video.
source§

async fn get_playlist_pos(&self) -> Result<usize, MpvError>

Get the current position in the playlist.
source§

async fn is_muted(&self) -> Result<bool, MpvError>

Check whether the player is muted.
source§

async fn is_playing(&self) -> Result<bool, MpvError>

Check whether the player is currently playing.
source§

async fn playlist_is_looping(&self) -> Result<LoopProperty, MpvError>

Check whether the player is looping the current playlist.
source§

async fn file_is_looping(&self) -> Result<LoopProperty, MpvError>

Check whether the player is looping the current video.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.