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
impl Mpv
Sourcepub fn create_event_context(&self) -> EventContext<'_>
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
impl Mpv
Sourcepub fn create_protocol_context<T, U>(&self) -> ProtocolContext<'_, T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
pub fn create_protocol_context<T, U>(&self) -> ProtocolContext<'_, T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
Create a context with which custom protocols can be registered.
§Panics
Panics if a context already exists
Source§impl Mpv
impl Mpv
Sourcepub fn new() -> Result<Mpv>
pub fn new() -> Result<Mpv>
Create a new Mpv
.
The default settings can be probed by running: $ mpv --show-profile=libmpv
.
Sourcepub fn with_initializer<F: FnOnce(MpvInitializer) -> Result<()>>(
initializer: F,
) -> Result<Mpv>
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.
Sourcepub fn load_config(&self, path: &str) -> Result<()>
pub fn load_config(&self, path: &str) -> Result<()>
Load a configuration file. The path has to be absolute, and a file.
Sourcepub fn command(&self, name: &str, args: &[&str]) -> Result<()>
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.
Sourcepub fn set_property<T: SetData>(&self, name: &str, data: T) -> Result<()>
pub fn set_property<T: SetData>(&self, name: &str, data: T) -> Result<()>
Set the value of a property.
Sourcepub fn get_property<T: GetData>(&self, name: &str) -> Result<T>
pub fn get_property<T: GetData>(&self, name: &str) -> Result<T>
Get the value of a property.
Sourcepub fn get_internal_time(&self) -> i64
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.
Sourcepub fn add_property(&self, property: &str, value: isize) -> Result<()>
pub fn add_property(&self, property: &str, value: isize) -> Result<()>
Add -or subtract- any value from a property. Over/underflow clamps to max/min.
Sourcepub fn cycle_property(&self, property: &str, up: bool) -> Result<()>
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.
Sourcepub fn multiply_property(&self, property: &str, factor: usize) -> Result<()>
pub fn multiply_property(&self, property: &str, factor: usize) -> Result<()>
Multiply any property with any positive factor.
Sourcepub fn seek_forward(&self, secs: c_double) -> Result<()>
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]).
Sourcepub fn seek_backward(&self, secs: c_double) -> Result<()>
pub fn seek_backward(&self, secs: c_double) -> Result<()>
See seek_forward
.
Sourcepub fn seek_absolute(&self, secs: c_double) -> Result<()>
pub fn seek_absolute(&self, secs: c_double) -> Result<()>
Seek to a given absolute secs.
Sourcepub fn seek_percent(&self, percent: isize) -> Result<()>
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.
Sourcepub fn seek_percent_absolute(&self, percent: usize) -> Result<()>
pub fn seek_percent_absolute(&self, percent: usize) -> Result<()>
Seek to the given percentage of the playtime.
Sourcepub fn seek_revert(&self) -> Result<()>
pub fn seek_revert(&self) -> Result<()>
Revert the previous seek_
call, can also revert itself.
Sourcepub fn seek_revert_mark(&self) -> Result<()>
pub fn seek_revert_mark(&self) -> Result<()>
Mark the current position as the position that will be seeked to by seek_revert
.
Sourcepub fn seek_frame(&self) -> Result<()>
pub fn seek_frame(&self) -> Result<()>
Seek exactly one frame, and pause. Noop on audio only streams.
Sourcepub fn seek_frame_backward(&self) -> Result<()>
pub fn seek_frame_backward(&self) -> Result<()>
See seek_frame
.
Note performance considerations.
Sourcepub fn screenshot_subtitles(&self, path: Option<&str>) -> Result<()>
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.”
Sourcepub fn screenshot_video(&self, path: Option<&str>) -> Result<()>
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.”
Sourcepub fn screenshot_window(&self, path: Option<&str>) -> Result<()>
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.”.
Sourcepub fn playlist_next_weak(&self) -> Result<()>
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.
Sourcepub fn playlist_next_force(&self) -> Result<()>
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.
Sourcepub fn playlist_previous_weak(&self) -> Result<()>
pub fn playlist_previous_weak(&self) -> Result<()>
See playlist_next_weak
.
Sourcepub fn playlist_previous_force(&self) -> Result<()>
pub fn playlist_previous_force(&self) -> Result<()>
See playlist_next_force
.
Sourcepub fn playlist_load_files(
&self,
files: &[(&str, FileState, Option<&str>)],
) -> Result<()>
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.
Sourcepub fn playlist_load_list(&self, path: &str, replace: bool) -> Result<()>
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.
Sourcepub fn playlist_clear(&self) -> Result<()>
pub fn playlist_clear(&self) -> Result<()>
Remove every, except the current, item from the playlist.
Sourcepub fn playlist_remove_current(&self) -> Result<()>
pub fn playlist_remove_current(&self) -> Result<()>
Remove the currently selected item from the playlist.
Sourcepub fn playlist_remove_index(&self, position: usize) -> Result<()>
pub fn playlist_remove_index(&self, position: usize) -> Result<()>
Remove item at position
from the playlist.
Sourcepub fn playlist_move(&self, old: usize, new: usize) -> Result<()>
pub fn playlist_move(&self, old: usize, new: usize) -> Result<()>
Move item old
to the position of item new
.
Sourcepub fn playlist_shuffle(&self) -> Result<()>
pub fn playlist_shuffle(&self) -> Result<()>
Shuffle the playlist.
Sourcepub fn subtitle_add_select(
&self,
path: &str,
title: Option<&str>,
lang: Option<&str>,
) -> Result<()>
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.
Sourcepub fn subtitle_add_auto(
&self,
path: &str,
title: Option<&str>,
lang: Option<&str>,
) -> Result<()>
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.
Sourcepub fn subtitle_add_cached(&self, path: &str) -> Result<()>
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.)”.
Sourcepub fn subtitle_remove(&self, index: Option<usize>) -> Result<()>
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.)”
Sourcepub fn subtitle_reload(&self, index: Option<usize>) -> Result<()>
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.)”
Sourcepub fn subtitle_step(&self, skip: isize) -> Result<()>
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.”
Sourcepub fn subtitle_seek_forward(&self) -> Result<()>
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.”
Sourcepub fn subtitle_seek_backward(&self) -> Result<()>
pub fn subtitle_seek_backward(&self) -> Result<()>
See SeekForward
.