44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Nim
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Nim
		
	
	
	
	
	
| import std/[os, uri]
 | |
| import mpv
 | |
| 
 | |
| import wdiwtlt/[models, db]
 | |
| 
 | |
| 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)
 |