pub struct MpvBackend {
mpv: Arc<Mpv>,
state: Arc<Mutex<InternalState>>,
event_emitter: Option<Arc<dyn PlayerEventEmitter>>,
audio_settings: AudioSettings,
playback_reporter: Arc<Mutex<Option<PlaybackReporter>>>,
position_throttler: Arc<EventThrottler>,
last_seek_time: Arc<AtomicU64>,
observed: Arc<Mutex<ObservedTime>>,
pending_seek: Arc<Mutex<Option<f64>>>,
}Expand description
MPV-based player backend for Linux
Uses libmpv for audio playback with full control over playback state, position tracking, and event handling.
Fields§
§mpv: Arc<Mpv>§state: Arc<Mutex<InternalState>>§event_emitter: Option<Arc<dyn PlayerEventEmitter>>§audio_settings: AudioSettings§playback_reporter: Arc<Mutex<Option<PlaybackReporter>>>§position_throttler: Arc<EventThrottler>§last_seek_time: Arc<AtomicU64>§observed: Arc<Mutex<ObservedTime>>Last position/duration seen while a file was loaded.
time-pos and duration are live properties of the loaded file: at
EOF MPV unloads it and both stop resolving, so reading them straight
through reported 0.0 / unknown exactly when end-of-file handling needed to
know where playback reached. See ObservedTime.
pending_seek: Arc<Mutex<Option<f64>>>A seek that arrived before MPV had a file to seek in.
loadfile is asynchronous: it returns as soon as the command is queued,
so time-pos is not yet a resolvable property and setting it fails. A
seek issued in that window used to be dropped on the floor, and the two
callers that do exactly this are the ones a viewer notices — resume, and
a transcoded seek, both of which re-open the stream and then ask for a
position. The stream reloaded and played from zero.
Held here and applied by the FileLoaded arm.
TRACES: UR-040, UR-005 | DR-241
Implementations§
Source§impl MpvBackend
impl MpvBackend
Sourcepub fn new(
event_emitter: Option<Arc<dyn PlayerEventEmitter>>,
playback_reporter: Arc<TokioMutex<Option<PlaybackReporter>>>,
position_throttler: Arc<EventThrottler>,
video_window: Option<i64>,
) -> Result<Self, PlayerError>
pub fn new( event_emitter: Option<Arc<dyn PlayerEventEmitter>>, playback_reporter: Arc<TokioMutex<Option<PlaybackReporter>>>, position_throttler: Arc<EventThrottler>, video_window: Option<i64>, ) -> Result<Self, PlayerError>
Create a new MPV backend
video_window is the app window’s native handle (an HWND), which mpv
draws video into on Windows; None elsewhere.
Sourcefn start_event_loop(&self)
fn start_event_loop(&self)
Start the MPV event loop in a background thread
Trait Implementations§
Source§impl Drop for MpvBackend
impl Drop for MpvBackend
Source§impl PlayerBackend for MpvBackend
impl PlayerBackend for MpvBackend
Source§fn position(&self) -> f64
fn position(&self) -> f64
Current position — the live time-pos, or the last one observed while a
file was loaded.
The fallback is the point: time-pos is a property of the loaded file,
so at EOF it stops resolving and a bare unwrap_or(0.0) reported 0:00 at
exactly the moment end-of-file handling asks where playback reached.
TRACES: UR-005 | DR-130 | UT-121
Source§fn duration(&self) -> Option<f64>
fn duration(&self) -> Option<f64>
Total duration — live, or the last one observed. Unloaded at EOF for the
same reason as position.
TRACES: UR-005 | DR-130 | UT-121
Source§fn set_audio_track(&mut self, stream_index: i32) -> Result<(), PlayerError>
fn set_audio_track(&mut self, stream_index: i32) -> Result<(), PlayerError>
stream_index is a position: the n-th audio track of the file, the
same meaning ExoPlayer gives it (player_switch_audio_track passes the
array index). Only reached for a direct play/stream — a transcode carries
one track and is re-opened instead.
TRACES: UR-021 | IR-019, DR-024, DR-235
Source§fn set_subtitle_track(
&mut self,
stream_index: Option<i32>,
) -> Result<(), PlayerError>
fn set_subtitle_track( &mut self, stream_index: Option<i32>, ) -> Result<(), PlayerError>
stream_index is the position in the sideloaded subtitle list the play
request carried (nativeSubtitleArrayIndex), None to hide subtitles.
TRACES: UR-020 | IR-018, DR-023, DR-235