diff --git a/src/core.rs b/src/core.rs index 5bf6b56..e63a879 100644 --- a/src/core.rs +++ b/src/core.rs @@ -364,7 +364,22 @@ pub struct EventManager<'a> { } impl<'a> EventManager<'a> { - pub fn attach(&self, event_type: EventType, callback: F) -> Result<(), InternalError> + pub fn detach(&self, event_type: EventType, registered_callback: *mut c_void) { + unsafe { + sys::libvlc_event_detach( + self.ptr, + event_type as i32, + Some(event_manager_callback), + registered_callback + ) + } + } + + pub fn attach( + &self, + event_type: EventType, + callback: F, + ) -> Result<*mut c_void, InternalError> where F: Fn(Event, VLCObject) + Send + 'static, { @@ -372,17 +387,19 @@ impl<'a> EventManager<'a> { let callback: Box> = Box::new(Box::new(callback)); + let raw = Box::into_raw(callback) as *mut c_void; + let result = unsafe { sys::libvlc_event_attach( self.ptr, event_type as i32, Some(event_manager_callback), - Box::into_raw(callback) as *mut c_void, + raw, ) }; if result == 0 { - Ok(()) + Ok(raw) } else { Err(InternalError) }