Crate libmpv_client

Source
Expand description

§libmpv-client

A Rust wrapper over libmpv.

The primary interface of this crate is Handle, start there.

Currently, only client.h is implemented, which is sufficient for writing mpv cplugins.

The latest rustdocs are hosted on GitHub Pages and are kept up to date with main. Due to limitations of this, documentation for other branches or tags much be built yourself. You can do this from your own crate with cargo doc -p libmpv-client.

§Windows Support

This crate supports the MPV_CPLUGIN_DYNAMIC_SYM function pointers provided by mpv, allowing for working DLLs on Windows.

§Installation

This crate is not yet hosted on crates.io. Until this changes, add the dependency by link to the Git repo:

[dependencies]
libmpv-client = { git = "https://github.com/astroftl/libmpv-client" }

# Specify the "next" branch for the latest and greatest.
libmpv-client = { git = "https://github.com/astroftl/libmpv-client", branch = "next" }

# Specify a tag to remain pinned to a specific version.
libmpv-client = { git = "https://github.com/astroftl/libmpv-client", tag = "0.2.0" }

§mpv cplugin Setup

To use this crate for mpv cplugins (which is its intended purpose), you have to create a Rust library crate with type cdylib.

In your Cargo.toml:

[lib]
crate-type = ["cdylib"]

§Example

use libmpv_client::*;

#[unsafe(no_mangle)]
extern "C" fn mpv_open_cplugin(ptr: *mut mpv_handle) -> std::os::raw::c_int {
    let handle = Handle::from_ptr(ptr);

    println!("Hello from Rust!");

    loop {
        match handle.wait_event(0.0) {
            Ok(event) => {
                match event {
                    Event::Shutdown => {
                        println!("Goodbye from Rust!");
                        return 0;
                    },
                    Event::None => {},
                    event => {
                        println!("Rust got event: {event:?}");
                    },
                }
            }
            Err(e) => {
                println!("Rust got error: {e:?}");
            }
        }
    }
}

Re-exports§

pub use handle::Handle;
pub use handle::Client;
pub use event::Event;
pub use event::EventId;
pub use error::Error;
pub use error::Result;
pub use types::*;

Modules§

error
The various errors that can be raised by this crate’s functions.
event
The various Events and their payloads which may be sent by mpv.
handle
Definition and implementation of Handle, this crate’s primary interface to mpv.
types
Definitions and trait implementations for the various types that can be used to communicate with mpv.
version
Various functions for ensuring that the currently used mpv player and header match the version this crate was intended for.

Macros§

node_array
Construct a NodeArray from a list of items that implement Into<Node>.
node_map
Construct a NodeMap from a list of (Into<String>, Into<Node>) tuples.

Structs§

mpv_handle
An opaque handle provided by mpv. Only useful when wrapped by Handle.