#7 Merge github patch
commit
b3e704eeae
23
src/core.rs
23
src/core.rs
|
@ -364,7 +364,22 @@ pub struct EventManager<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> EventManager<'a> {
|
impl<'a> EventManager<'a> {
|
||||||
pub fn attach<F>(&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<F>(
|
||||||
|
&self,
|
||||||
|
event_type: EventType,
|
||||||
|
callback: F,
|
||||||
|
) -> Result<*mut c_void, InternalError>
|
||||||
where
|
where
|
||||||
F: Fn(Event, VLCObject) + Send + 'static,
|
F: Fn(Event, VLCObject) + Send + 'static,
|
||||||
{
|
{
|
||||||
|
@ -372,17 +387,19 @@ impl<'a> EventManager<'a> {
|
||||||
let callback: Box<Box<dyn Fn(Event, VLCObject) + Send + 'static>> =
|
let callback: Box<Box<dyn Fn(Event, VLCObject) + Send + 'static>> =
|
||||||
Box::new(Box::new(callback));
|
Box::new(Box::new(callback));
|
||||||
|
|
||||||
|
let raw = Box::into_raw(callback) as *mut c_void;
|
||||||
|
|
||||||
let result = unsafe {
|
let result = unsafe {
|
||||||
sys::libvlc_event_attach(
|
sys::libvlc_event_attach(
|
||||||
self.ptr,
|
self.ptr,
|
||||||
event_type as i32,
|
event_type as i32,
|
||||||
Some(event_manager_callback),
|
Some(event_manager_callback),
|
||||||
Box::into_raw(callback) as *mut c_void,
|
raw,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
Ok(())
|
Ok(raw)
|
||||||
} else {
|
} else {
|
||||||
Err(InternalError)
|
Err(InternalError)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue