diff options
author | wm4 <wm4@nowhere> | 2015-01-01 23:07:46 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-01-01 23:08:15 +0100 |
commit | da4f7225796037b814919e79912cfaa7a9ddc113 (patch) | |
tree | 74b3ed6bcfdc5648ab03dcd656f67f7720610392 /DOCS/client_api_examples/simple | |
parent | 9aa1d711479d4892e7f3c528dd48aad91f8a63de (diff) | |
download | mpv-da4f7225796037b814919e79912cfaa7a9ddc113.tar.bz2 mpv-da4f7225796037b814919e79912cfaa7a9ddc113.tar.xz |
DOCS/client_api_examples: move all examples into their own subdirs
Also get rid of shared.h; it actually doesn't have much value. Just copy
the tiny function it contained into the 2 files which used it.
Diffstat (limited to 'DOCS/client_api_examples/simple')
-rw-r--r-- | DOCS/client_api_examples/simple/simple.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/DOCS/client_api_examples/simple/simple.c b/DOCS/client_api_examples/simple/simple.c new file mode 100644 index 0000000000..62fc9e8061 --- /dev/null +++ b/DOCS/client_api_examples/simple/simple.c @@ -0,0 +1,52 @@ +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> + +#include "libmpv/client.h" + +static inline void check_error(int status) +{ + if (status < 0) { + printf("mpv API error: %s\n", mpv_error_string(status)); + exit(1); + } +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + printf("pass a single media file as argument\n"); + return 1; + } + + mpv_handle *ctx = mpv_create(); + if (!ctx) { + printf("failed creating context\n"); + return 1; + } + + // Enable default key bindings, so the user can actually interact with + // the player (and e.g. close the window). + check_error(mpv_set_option_string(ctx, "input-default-bindings", "yes")); + mpv_set_option_string(ctx, "input-x11-keyboard", "yes"); + int val = 1; + check_error(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &val)); + + // Done setting up options. + check_error(mpv_initialize(ctx)); + + // Play this file. + const char *cmd[] = {"loadfile", argv[1], NULL}; + check_error(mpv_command(ctx, cmd)); + + // Let it play, and wait until the user quits. + while (1) { + mpv_event *event = mpv_wait_event(ctx, 10000); + printf("event: %s\n", mpv_event_name(event->event_id)); + if (event->event_id == MPV_EVENT_SHUTDOWN) + break; + } + + mpv_terminate_destroy(ctx); + return 0; +} |