From bad288a24ba317be45bde9bb7c2d37dba6719c52 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Thu, 20 Feb 2025 22:25:30 -0600 Subject: [PATCH] Proof-of-concept MPV-based player. --- src/main/nim/wdiwtlt.nim | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/nim/wdiwtlt.nim diff --git a/src/main/nim/wdiwtlt.nim b/src/main/nim/wdiwtlt.nim new file mode 100644 index 0000000..cf58fee --- /dev/null +++ b/src/main/nim/wdiwtlt.nim @@ -0,0 +1,41 @@ +import std/[os, uri] +import mpv + +when isMainModule: + var ctx: ptr handle + try: + if paramCount() != 1: + echo "pass a single media file as argument" + quit(QuitFailure) + + ctx = mpv.create() + if ctx.isNil: + echo "failed creating mpv context" + quit(QuitFailure) + + # Enable default key bindings, so the user can actually interact with + # the player (and e.g. close the window). + ctx.set_option("terminal", "no") + ctx.set_option("input-default-bindings", "yes") + ctx.set_option("input-vo-keyboard", "yes") + ctx.set_option("osc", false) + ctx.set_property("volume", "50.0") + discard ctx.request_log_messages("no") + + # Done setting up options. + check_error ctx.initialize() + + # Play this file. + discard ctx.command_string("loadfile " & "file://" & encodeUrl(paramStr(1), false)) + # discard ctx.command_string(["loadfile ", "file://" & encodeUrl(paramStr(1), false)]) + + while true: + let event = ctx.wait_event(10000) + echo "event: ", mpv.event_name(event.event_id) + if event.event_id == mpv.EVENT_SHUTDOWN: + break + except Exception: + echo "wdiwtlt: " & getCurrentExceptionMsg() + quit(QuitFailure) + finally: + mpv.terminate_destroy(ctx)