Skip to content

Commit

Permalink
DELETEME: simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
t-8ch committed Feb 25, 2023
1 parent 9e84e19 commit f4269fa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions libmpv/simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Build with: gcc -o simple simple.c `pkg-config --libs --cflags mpv`

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#include "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-vo-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;
}
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,8 @@ if get_option('libmpv')

libmpv_test = executable('libmpv-test', 'libmpv/test.c', link_with: [libmpv])
test('libmpv', libmpv_test)

executable('libmpv-simple', 'libmpv/simple.c', link_with: [libmpv])
endif

if get_option('cplayer')
Expand Down

0 comments on commit f4269fa

Please sign in to comment.