diff options
Diffstat (limited to 'crates/libmpv2/src/mpv')
-rw-r--r-- | crates/libmpv2/src/mpv/events.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/crates/libmpv2/src/mpv/events.rs b/crates/libmpv2/src/mpv/events.rs index cbe1ef3..6fb4683 100644 --- a/crates/libmpv2/src/mpv/events.rs +++ b/crates/libmpv2/src/mpv/events.rs @@ -41,6 +41,20 @@ pub mod mpv_event_id { pub use libmpv2_sys::mpv_event_id_MPV_EVENT_VIDEO_RECONFIG as VideoReconfig; } +/// A unique id of every entry MPV has loaded +#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Hash)] +pub struct PlaylistEntryId(i64); +impl PlaylistEntryId { + pub fn new(val: i64) -> Self { + Self(val) + } +} +impl Display for PlaylistEntryId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + #[derive(Debug)] /// Data that is returned by both `GetPropertyReply` and `PropertyChange` events. pub enum PropertyData<'a> { @@ -80,7 +94,11 @@ impl<'a> PropertyData<'a> { } } -pub type PlaylistEntryId = i64; +#[derive(Debug)] +pub struct EndFileEvent { + pub reason: EndFileReason, + pub playlist_entry_id: PlaylistEntryId, +} #[derive(Debug)] pub enum Event<'a> { @@ -106,7 +124,7 @@ pub enum Event<'a> { /// Event received when a new file is playing StartFile(PlaylistEntryId), /// Event received when the file being played currently has stopped, for an error or not - EndFile(EndFileReason), + EndFile(EndFileEvent), /// Event received when a file has been *loaded*, but has not been started FileLoaded, ClientMessage(Vec<&'a str>), @@ -270,7 +288,7 @@ impl EventContext { mpv_event_id::StartFile => { let playlist_id = unsafe { *(event.data as *mut i64) }; - Some(Ok(Event::StartFile(playlist_id))) + Some(Ok(Event::StartFile(PlaylistEntryId(playlist_id)))) } mpv_event_id::EndFile => { let end_file = unsafe { *(event.data as *mut libmpv2_sys::mpv_event_end_file) }; @@ -280,7 +298,11 @@ impl EventContext { if let Err(e) = mpv_err((), end_file.error) { Some(Err(e)) } else { - Some(Ok(Event::EndFile(end_file.reason.into()))) + let event = EndFileEvent { + reason: end_file.reason.into(), + playlist_entry_id: PlaylistEntryId(end_file.playlist_entry_id), + }; + Some(Ok(Event::EndFile(event))) } } mpv_event_id::FileLoaded => Some(Ok(Event::FileLoaded)), |