Struct mpvipc::Mpv

source ·
pub struct Mpv { /* private fields */ }

Implementations§

source§

impl Mpv

source

pub fn connect(socket: &str) -> Result<Mpv, Error>

source

pub fn disconnect(&self)

source

pub fn get_stream_ref(&self) -> &UnixStream

source

pub fn get_metadata(&self) -> Result<HashMap<String, MpvDataType>, Error>

source

pub fn get_playlist(&self) -> Result<Playlist, Error>

source

pub fn get_property<T: GetPropertyTypeHandler>( &self, property: &str ) -> Result<T, Error>

Description

Retrieves the property value from mpv.

Supported types
  • String
  • bool
  • HashMap<String, String> (e.g. for the ‘metadata’ property)
  • Vec (for the ‘playlist’ property)
  • usize
  • f64
Input arguments
  • property defines the mpv property that should be retrieved
Example
use mpvipc::{Mpv, Error};
fn main() -> Result<(), Error> {
    let mpv = Mpv::connect("/tmp/mpvsocket")?;
    let paused: bool = mpv.get_property("pause")?;
    let title: String = mpv.get_property("media-title")?;
    Ok(())
}
source

pub fn get_property_string(&self, property: &str) -> Result<String, Error>

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::{Mpv, Error};
fn main() -> Result<(), Error> {
    let mpv = Mpv::connect("/tmp/mpvsocket")?;
    let title = mpv.get_property_string("media-title")?;
    Ok(())
}
source

pub fn kill(&self) -> Result<(), Error>

source

pub fn event_listen(&mut self) -> Result<Event, Error>

Description

Waits until an mpv event occurs and returns the Event.

Example
let mut mpv = Mpv::connect("/tmp/mpvsocket")?;
loop {
    let event = mpv.event_listen()?;
    println!("{:?}", event);
}
source

pub fn event_listen_raw(&mut self) -> String

source

pub fn next(&self) -> Result<(), Error>

source

pub fn observe_property(&self, id: isize, property: &str) -> Result<(), Error>

source

pub fn unobserve_property(&self, id: isize) -> Result<(), Error>

source

pub fn pause(&self) -> Result<(), Error>

source

pub fn prev(&self) -> Result<(), Error>

source

pub fn restart(&self) -> Result<(), Error>

source

pub fn run_command(&self, command: MpvCommand) -> Result<(), Error>

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::{Mpv, Error};
fn main() -> Result<(), Error> {
    let mpv = Mpv::connect("/tmp/mpvsocket")?;

    //Run command 'playlist-shuffle' which takes no arguments
    mpv.run_command(MpvCommand::PlaylistShuffle)?;

    //Run command 'seek' which in this case takes two arguments
    mpv.run_command(MpvCommand::Seek {
        seconds: 0f64,
        option: SeekOptions::Absolute,
    })?;
    Ok(())
}
source

pub fn run_command_raw(&self, command: &str, args: &[&str]) -> Result<(), Error>

Run a custom command. This should only be used if the desired command is not implemented with MpvCommand.

source

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

source

pub fn playlist_clear(&self) -> Result<(), Error>

source

pub fn playlist_move_id(&self, from: usize, to: usize) -> Result<(), Error>

source

pub fn playlist_play_id(&self, id: usize) -> Result<(), Error>

source

pub fn playlist_play_next(&self, id: usize) -> Result<(), Error>

source

pub fn playlist_remove_id(&self, id: usize) -> Result<(), Error>

source

pub fn playlist_shuffle(&self) -> Result<(), Error>

source

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

source

pub fn set_loop_file(&self, option: Switch) -> Result<(), Error>

source

pub fn set_loop_playlist(&self, option: Switch) -> Result<(), Error>

source

pub fn set_mute(&self, option: Switch) -> Result<(), Error>

source

pub fn set_property<T: SetPropertyTypeHandler<T>>( &self, property: &str, value: T ) -> Result<(), Error>

Description

Sets the mpv property to .

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
Example
use mpvipc::{Mpv, Error};
fn main() -> Result<(), Error> {
    let mpv = Mpv::connect("/tmp/mpvsocket")?;
    mpv.set_property("pause", true)?;
    Ok(())
}
source

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

source

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

source

pub fn stop(&self) -> Result<(), Error>

source

pub fn toggle(&self) -> Result<(), Error>

Trait Implementations§

source§

impl Clone for Mpv

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
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 Drop for Mpv

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.