2015-01-23 14:32:23 +00:00
|
|
|
// Build with: gcc -o simple simple.c `pkg-config --libs --cflags mpv`
|
|
|
|
|
2014-02-10 20:30:55 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-01-01 22:56:41 +00:00
|
|
|
#include <mpv/client.h>
|
2015-01-01 22:07:46 +00:00
|
|
|
|
|
|
|
static inline void check_error(int status)
|
|
|
|
{
|
|
|
|
if (status < 0) {
|
|
|
|
printf("mpv API error: %s\n", mpv_error_string(status));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 20:30:55 +00:00
|
|
|
|
|
|
|
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"));
|
2015-02-23 15:08:38 +00:00
|
|
|
mpv_set_option_string(ctx, "input-vo-keyboard", "yes");
|
2014-02-24 22:02:50 +00:00
|
|
|
int val = 1;
|
|
|
|
check_error(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &val));
|
2014-02-10 20:30:55 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2014-06-07 18:25:48 +00:00
|
|
|
mpv_terminate_destroy(ctx);
|
2014-02-10 20:30:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|