Struct Mpv

Source
pub struct Mpv {
    pub ctx: NonNull<mpv_handle>,
    /* private fields */
}
Expand description

The central mpv context.

Fields§

§ctx: NonNull<mpv_handle>

The handle to the mpv core

Implementations§

Source§

impl Mpv

Source

pub fn create_event_context(&self) -> EventContext<'_>

Create a context that can be used to wait for events and control which events are listened for.

§Panics

Panics if a context already exists

Source§

impl Mpv

Source

pub fn create_protocol_context<T, U>(&self) -> ProtocolContext<'_, T, U>

Create a context with which custom protocols can be registered.

§Panics

Panics if a context already exists

Source§

impl Mpv

Source

pub fn new() -> Result<Mpv>

Create a new Mpv. The default settings can be probed by running: $ mpv --show-profile=libmpv.

Source

pub fn with_initializer<F: FnOnce(MpvInitializer) -> Result<()>>( initializer: F, ) -> Result<Mpv>

Create a new Mpv. The same as Mpv::new, but you can set properties before Mpv is initialized.

Source

pub fn load_config(&self, path: &str) -> Result<()>

Load a configuration file. The path has to be absolute, and a file.

Source

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

Send a command to the Mpv instance. This uses mpv_command_string internally, so that the syntax is the same as described in the manual for the input.conf.

Note that you may have to escape strings with "" when they contain spaces.

Source

pub fn set_property<T: SetData>(&self, name: &str, data: T) -> Result<()>

Set the value of a property.

Source

pub fn get_property<T: GetData>(&self, name: &str) -> Result<T>

Get the value of a property.

Source

pub fn get_internal_time(&self) -> i64

Internal time in microseconds, this has an arbitrary offset, and will never go backwards.

This can be called at any time, even if it was stated that no API function should be called.

Source

pub fn add_property(&self, property: &str, value: isize) -> Result<()>

Add -or subtract- any value from a property. Over/underflow clamps to max/min.

Source

pub fn cycle_property(&self, property: &str, up: bool) -> Result<()>

Cycle through a given property. up specifies direction. On overflow, set the property back to the minimum, on underflow set it to the maximum.

Source

pub fn multiply_property(&self, property: &str, factor: usize) -> Result<()>

Multiply any property with any positive factor.

Source

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

Pause playback at runtime.

Source

pub fn unpause(&self) -> Result<()>

Unpause playback at runtime.

Source

pub fn seek_forward(&self, secs: c_double) -> Result<()>

Seek forward relatively from current position in seconds. This is less exact than seek_absolute, see [mpv manual] (https://mpv.io/manual/master/#command-interface- [relative|absolute|absolute-percent|relative-percent|exact|keyframes]).

Source

pub fn seek_backward(&self, secs: c_double) -> Result<()>

See seek_forward.

Source

pub fn seek_absolute(&self, secs: c_double) -> Result<()>

Seek to a given absolute secs.

Source

pub fn seek_percent(&self, percent: isize) -> Result<()>

Seek to a given relative percent position (may be negative). If percent of the playtime is bigger than the remaining playtime, the next file is played. out of bounds values are clamped to either 0 or 100.

Source

pub fn seek_percent_absolute(&self, percent: usize) -> Result<()>

Seek to the given percentage of the playtime.

Source

pub fn seek_revert(&self) -> Result<()>

Revert the previous seek_ call, can also revert itself.

Source

pub fn seek_revert_mark(&self) -> Result<()>

Mark the current position as the position that will be seeked to by seek_revert.

Source

pub fn seek_frame(&self) -> Result<()>

Seek exactly one frame, and pause. Noop on audio only streams.

Source

pub fn seek_frame_backward(&self) -> Result<()>

Source

pub fn screenshot_subtitles(&self, path: Option<&str>) -> Result<()>

“Save the video image, in its original resolution, and with subtitles. Some video outputs may still include the OSD in the output under certain circumstances.”.

“[O]ptionally save it to a given file. The format of the file will be guessed by the extension (and –screenshot-format is ignored - the behaviour when the extension is missing or unknown is arbitrary). If the file already exists, it’s overwritten. Like all input command parameters, the filename is subject to property expansion as described in Property Expansion.”

Source

pub fn screenshot_video(&self, path: Option<&str>) -> Result<()>

“Like subtitles, but typically without OSD or subtitles. The exact behavior depends on the selected video output.”

Source

pub fn screenshot_window(&self, path: Option<&str>) -> Result<()>

“Save the contents of the mpv window. Typically scaled, with OSD and subtitles. The exact behaviour depends on the selected video output, and if no support is available, this will act like video.”.

Source

pub fn playlist_next_weak(&self) -> Result<()>

Play the next item of the current playlist. Does nothing if the current item is the last item.

Source

pub fn playlist_next_force(&self) -> Result<()>

Play the next item of the current playlist. Terminates playback if the current item is the last item.

Source

pub fn playlist_previous_weak(&self) -> Result<()>

See playlist_next_weak.

Source

pub fn playlist_previous_force(&self) -> Result<()>

See playlist_next_force.

Source

pub fn playlist_load_files( &self, files: &[(&str, FileState, Option<&str>)], ) -> Result<()>

The given files are loaded sequentially, returning the index of the current file and the error in case of an error. More information.

§Arguments

The files tuple slice consists of: * a string slice - the path * a FileState - how the file will be opened * an optional string slice - any additional options that will be set for this file

§Peculiarities

loadfile is kind of asynchronous, any additional option is set during loading, specifics.

Source

pub fn playlist_load_list(&self, path: &str, replace: bool) -> Result<()>

Load the given playlist file, that either replaces the current playlist, or appends to it.

Source

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

Remove every, except the current, item from the playlist.

Source

pub fn playlist_remove_current(&self) -> Result<()>

Remove the currently selected item from the playlist.

Source

pub fn playlist_remove_index(&self, position: usize) -> Result<()>

Remove item at position from the playlist.

Source

pub fn playlist_move(&self, old: usize, new: usize) -> Result<()>

Move item old to the position of item new.

Source

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

Shuffle the playlist.

Source

pub fn subtitle_add_select( &self, path: &str, title: Option<&str>, lang: Option<&str>, ) -> Result<()>

Add and select the subtitle immediately. Specifying a language requires specifying a title.

§Panics

If a language but not title was specified.

Source

pub fn subtitle_add_auto( &self, path: &str, title: Option<&str>, lang: Option<&str>, ) -> Result<()>

See AddSelect. “Don’t select the subtitle. (Or in some special situations, let the default stream selection mechanism decide.)”.

Returns an Error::InvalidArgument if a language, but not a title, was provided.

§Panics

If a language but not title was specified.

Source

pub fn subtitle_add_cached(&self, path: &str) -> Result<()>

See AddSelect. “Select the subtitle. If a subtitle with the same file name was already added, that one is selected, instead of loading a duplicate entry. (In this case, title/language are ignored, and if the [sub] was changed since it was loaded, these changes won’t be reflected.)”.

Source

pub fn subtitle_remove(&self, index: Option<usize>) -> Result<()>

“Remove the given subtitle track. If the id argument is missing, remove the current track. (Works on external subtitle files only.)”

Source

pub fn subtitle_reload(&self, index: Option<usize>) -> Result<()>

“Reload the given subtitle track. If the id argument is missing, reload the current track. (Works on external subtitle files only.)”

Source

pub fn subtitle_step(&self, skip: isize) -> Result<()>

“Change subtitle timing such, that the subtitle event after the next isize subtitle events is displayed. isize can be negative to step backwards.”

Source

pub fn subtitle_seek_forward(&self) -> Result<()>

“Seek to the next subtitle. This is similar to sub-step, except that it seeks video and audio instead of adjusting the subtitle delay. For embedded subtitles (like with matroska), this works only with subtitle events that have already been displayed, or are within a short prefetch range.”

Source

pub fn subtitle_seek_backward(&self) -> Result<()>

See SeekForward.

Trait Implementations§

Source§

impl Drop for Mpv

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Mpv

Source§

impl Sync for Mpv

Auto Trait Implementations§

§

impl !Freeze for Mpv

§

impl RefUnwindSafe 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> 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, 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.