sanity check
This commit is contained in:
parent
ec0992ce54
commit
d4a2996eac
2 changed files with 22 additions and 1 deletions
|
@ -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<Self, Error> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<String>("path").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
_ => println!("mpv event {:?}", event),
|
||||
|
|
Loading…
Reference in a new issue