summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-01-12 18:04:52 +0100
committerwm4 <wm4@nowhere>2017-01-12 18:04:52 +0100
commitf2e24d5f8ab2237341d7435b0ba766e4bbc6bf3f (patch)
treeb188c5678991bc0c7fe9c2a084246546ecc9cd73
parent656341a0f52cc7e7f4404865c63c9339ea05f181 (diff)
downloadmpv-examples-f2e24d5f8ab2237341d7435b0ba766e4bbc6bf3f.tar.bz2
mpv-examples-f2e24d5f8ab2237341d7435b0ba766e4bbc6bf3f.tar.xz
Add cplugin example
-rw-r--r--cplugins/README.md13
-rw-r--r--cplugins/simple/simple.c23
2 files changed, 36 insertions, 0 deletions
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 <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <mpv/client.h>
+
+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;
+}
+