Proof-of-concept MPV-based player.

This commit is contained in:
Jonathan Bernard 2025-02-20 22:25:30 -06:00
parent bbd7952232
commit bad288a24b

41
src/main/nim/wdiwtlt.nim Normal file
View File

@ -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)