tauri-plugin-libmpv 0.3.2

A Tauri plugin for embedding the mpv player in your app via libmpv.
Documentation
/* automatically generated by rust-bindgen 0.72.1 */

/* Run 'cargo run -p codegen' to regenerate */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct MpvHandle {
    _unused: [u8; 0],
}
/** Callback function type for mpv events.

 @param event A JSON string representing the event.
 @param userdata The user-supplied pointer passed to `mpv_wrapper_create`.*/
pub type EventCallback = ::std::option::Option<
    unsafe extern "C" fn(
        event: *const ::std::os::raw::c_char,
        userdata: *mut ::std::os::raw::c_void,
    ),
>;
pub struct LibmpvWrapper {
    __library: ::libloading::Library,
    pub mpv_wrapper_create: unsafe extern "C" fn(
        initial_options: *const ::std::os::raw::c_char,
        observed_properties: *const ::std::os::raw::c_char,
        event_callback: EventCallback,
        event_userdata: *mut ::std::os::raw::c_void,
    ) -> *mut MpvHandle,
    pub mpv_wrapper_destroy: unsafe extern "C" fn(handle: *mut MpvHandle),
    pub mpv_wrapper_command: unsafe extern "C" fn(
        handle: *mut MpvHandle,
        name: *const ::std::os::raw::c_char,
        args: *const ::std::os::raw::c_char,
    ) -> *mut ::std::os::raw::c_char,
    pub mpv_wrapper_set_property: unsafe extern "C" fn(
        handle: *mut MpvHandle,
        name: *const ::std::os::raw::c_char,
        value: *const ::std::os::raw::c_char,
    ) -> *mut ::std::os::raw::c_char,
    pub mpv_wrapper_get_property: unsafe extern "C" fn(
        handle: *mut MpvHandle,
        name: *const ::std::os::raw::c_char,
        format: *const ::std::os::raw::c_char,
    ) -> *mut ::std::os::raw::c_char,
    pub mpv_wrapper_free: unsafe extern "C" fn(s: *mut ::std::os::raw::c_char),
}
impl LibmpvWrapper {
    pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
    where
        P: AsRef<::std::ffi::OsStr>,
    {
        let library = unsafe { ::libloading::Library::new(path) }?;
        unsafe { Self::from_library(library) }
    }
    pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
    where
        L: Into<::libloading::Library>,
    {
        let __library = library.into();
        let mpv_wrapper_create = unsafe { __library.get(b"mpv_wrapper_create\0") }
            .map(|sym| *sym)?;
        let mpv_wrapper_destroy = unsafe { __library.get(b"mpv_wrapper_destroy\0") }
            .map(|sym| *sym)?;
        let mpv_wrapper_command = unsafe { __library.get(b"mpv_wrapper_command\0") }
            .map(|sym| *sym)?;
        let mpv_wrapper_set_property = unsafe {
            __library.get(b"mpv_wrapper_set_property\0")
        }
            .map(|sym| *sym)?;
        let mpv_wrapper_get_property = unsafe {
            __library.get(b"mpv_wrapper_get_property\0")
        }
            .map(|sym| *sym)?;
        let mpv_wrapper_free = unsafe { __library.get(b"mpv_wrapper_free\0") }
            .map(|sym| *sym)?;
        Ok(LibmpvWrapper {
            __library,
            mpv_wrapper_create,
            mpv_wrapper_destroy,
            mpv_wrapper_command,
            mpv_wrapper_set_property,
            mpv_wrapper_get_property,
            mpv_wrapper_free,
        })
    }
    /** Creates a new mpv handle.

 @param initial_options A JSON string of initial mpv options (e.g., `{"idle": "yes"}`).
 @param observed_properties A JSON string mapping property names to their formats (e.g., `{"pause": "flag"}`).
                            The format can be "string", "flag", "int64", "double", or "node".
 @param event_callback A function pointer that will be called for mpv events.
 @param event_userdata A user-supplied pointer that will be passed to the event_callback.
 @return A pointer to the opaque mpv handle, or NULL on failure.*/
    pub unsafe fn mpv_wrapper_create(
        &self,
        initial_options: *const ::std::os::raw::c_char,
        observed_properties: *const ::std::os::raw::c_char,
        event_callback: EventCallback,
        event_userdata: *mut ::std::os::raw::c_void,
    ) -> *mut MpvHandle {
        unsafe {
            (self
                .mpv_wrapper_create)(
                initial_options,
                observed_properties,
                event_callback,
                event_userdata,
            )
        }
    }
    /** Destroys the mpv handle and terminates the mpv core.

 @param handle A valid pointer to the mpv handle (obtained from `mpv_wrapper_create`).*/
    pub unsafe fn mpv_wrapper_destroy(&self, handle: *mut MpvHandle) {
        unsafe { (self.mpv_wrapper_destroy)(handle) }
    }
    /** Executes an mpv command.

 @param handle A valid pointer to the mpv handle.
 @param name The name of the command (e.g., "set", "loadfile").
 @param args A JSON string representing an array of arguments (e.g., `["volume", "50"]`, `["path/to/video.mp4"]`).
             Pass an empty string "[]" or NULL for no arguments.
 @return A JSON string representing the command result (e.g., `{"data": null}` or `{"error": "..."}`).
         The caller MUST free this string using `mpv_wrapper_free_string`.*/
    pub unsafe fn mpv_wrapper_command(
        &self,
        handle: *mut MpvHandle,
        name: *const ::std::os::raw::c_char,
        args: *const ::std::os::raw::c_char,
    ) -> *mut ::std::os::raw::c_char {
        unsafe { (self.mpv_wrapper_command)(handle, name, args) }
    }
    /** Sets an mpv property.

 @param handle A valid pointer to the mpv handle.
 @param name The name of the property to set (e.g., "pause").
 @param value A JSON string representing the value (e.g., "true").
 @return A JSON string indicating success or failure.
         The caller MUST free this string using `mpv_wrapper_free_string`.*/
    pub unsafe fn mpv_wrapper_set_property(
        &self,
        handle: *mut MpvHandle,
        name: *const ::std::os::raw::c_char,
        value: *const ::std::os::raw::c_char,
    ) -> *mut ::std::os::raw::c_char {
        unsafe { (self.mpv_wrapper_set_property)(handle, name, value) }
    }
    /** Gets an mpv property.

 @param handle A valid pointer to the mpv handle.
 @param name The name of the property to get.
 @param format The format can be "string", "flag", "int64", "double", or "node".
 @return A JSON string containing the property value (e.g., `{"data": true}`) or an error.
         The caller MUST free this string using `mpv_wrapper_free_string`.*/
    pub unsafe fn mpv_wrapper_get_property(
        &self,
        handle: *mut MpvHandle,
        name: *const ::std::os::raw::c_char,
        format: *const ::std::os::raw::c_char,
    ) -> *mut ::std::os::raw::c_char {
        unsafe { (self.mpv_wrapper_get_property)(handle, name, format) }
    }
    /** Frees a C string that was returned by one of the `mpv_wrapper_*` functions.

 @param s A pointer to the C string to be freed.*/
    pub unsafe fn mpv_wrapper_free(&self, s: *mut ::std::os::raw::c_char) {
        unsafe { (self.mpv_wrapper_free)(s) }
    }
}