From d4a2996eacb45c9a8dd3bcf443c82a7a0f74db4b Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sun, 3 Nov 2024 18:50:49 +0100 Subject: [PATCH] sanity check --- src/mpv/format.rs | 17 ++++++++++++++++- src/playbin2.rs | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/mpv/format.rs b/src/mpv/format.rs index 57c4bd1..b51d02f 100644 --- a/src/mpv/format.rs +++ b/src/mpv/format.rs @@ -1,5 +1,5 @@ use super::{ffi, Error}; -use std::ffi::{c_char, c_int, c_void, CString}; +use std::ffi::{c_char, c_int, c_void, CStr, CString}; pub trait SetProperty { /// # Safety @@ -121,3 +121,18 @@ impl GetProperty for i64 { Ok(value) } } + +impl GetProperty for String { + unsafe fn get_property(ctx: *mut ffi::mpv_handle, name: *const c_char) -> Result { + let mut value: *mut c_char = std::ptr::null_mut(); + Error::from_return_code(ffi::mpv_get_property( + ctx, + name, + ffi::mpv_format_MPV_FORMAT_STRING, + std::ptr::from_mut::<*mut c_char>(&mut value) as *mut c_void, + ))?; + let result = CStr::from_ptr(value).to_string_lossy().into_owned(); + ffi::mpv_free(value as *mut c_void); + Ok(result) + } +} diff --git a/src/playbin2.rs b/src/playbin2.rs index 05c9b91..f6f96cf 100644 --- a/src/playbin2.rs +++ b/src/playbin2.rs @@ -229,6 +229,12 @@ where // since we set up the hook before, the current song is guaranteed not to change // under our feet self.file_started.emit(self, ()); + + // sanity check + assert_eq!( + self.entries()[self.current_entry().unwrap()].url().as_str(), + &self.mpv.get_property::("path").unwrap() + ); } _ => println!("mpv event {:?}", event),