From f2e24d5f8ab2237341d7435b0ba766e4bbc6bf3f Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 12 Jan 2017 18:04:52 +0100 Subject: Add cplugin example --- cplugins/README.md | 13 +++++++++++++ cplugins/simple/simple.c | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 cplugins/README.md create mode 100644 cplugins/simple/simple.c diff --git a/cplugins/README.md b/cplugins/README.md new file mode 100644 index 0000000..06223e0 --- /dev/null +++ b/cplugins/README.md @@ -0,0 +1,13 @@ +# C plugin examples + +Documentation is here: https://mpv.io/manual/master/#c-plugins + +Other than this, the normal libmpv documentation applies. +Very primitive terminal-only example. Shows some most basic API usage. + +## List of Examples + +### simple + +Very primitive example showing basic API usage. + diff --git a/cplugins/simple/simple.c b/cplugins/simple/simple.c new file mode 100644 index 0000000..c8c6de8 --- /dev/null +++ b/cplugins/simple/simple.c @@ -0,0 +1,23 @@ +// Build with: gcc -o simple.so simple.c `pkg-config --cflags mpv` -shared -fPIC +// Warning: do not link against libmpv.so! Read: +// https://mpv.io/manual/master/#linkage-to-libmpv +// The pkg-config call is for adding the proper client.h include path. + +#include +#include +#include + +#include + +int mpv_open_cplugin(mpv_handle *handle) +{ + printf("Hello world from C plugin '%s'!\n", mpv_client_name(handle)); + while (1) { + mpv_event *event = mpv_wait_event(handle, -1); + printf("Got event: %d\n", event->event_id); + if (event->event_id == MPV_EVENT_SHUTDOWN) + break; + } + return 0; +} + -- cgit v1.2.3