Megawidget mplayer

wdb This rustical megawidget makes mplayer controllable via Tcl/Tk. Built and tested on Linux; functional test on Windows is up to you.

Procedure mplayer makes a frame with classname Mplayer with attribute -container set to yes, starting a piped instance of mplayer with arguments described below. The resulting command, eg. .movieframe, is then renamed to _.movieframe, and newly defined procedure .movieframe has additional sub-command cmd which sends commands to mplayer instance.

To see list of all commands, enter:

 mplayer -input cmdlist

Description of commands see here or here .

Key bindings on .movieframe are made according to original key bindings.

Destroying .movieframe sends cmd quit to mplayer, then closes the pipe, then renames procedure .movieframe to empty string.

Creating the frame occurs as in in this example:

 % mplayer .movieframe -width 400 -height 300 -- -nosound {*}[glob *.mp4] 
 % _

Explanation: first attributes for Tk frame, then two hyphens --, then arguments to start the mplayer instance. If no switches for mplayer intended, -- can be omitted.

Have fun!

proc mplayer {f args} {
  set options {-width 600 -height 400}
  while {[string match -* $args]} {
    if {[lindex $args 0] eq "--"} then {
      set args [lrange $args 1 end]
    } else {
      set args [lassign $args key val]
      dict set options $key $val
  frame $f -class Mplayer -container yes {*}$options
  set wid [winfo id $f]
  set channel\
    [open [concat | mplayer -quiet -idle -slave -wid $wid $args] r+]
  flush $channel
  bind $f <Destroy> [subst {
      catch {
        rename $f ""
        puts $channel quit
        flush $channel
        close $channel
  rename $f _$f
  proc $f {cmd args} [subst -nocommand {
      if {\$cmd eq "cmd"} then {
        puts $channel \$args
        flush $channel
      } else {
        _$f \$cmd [list \$args]
  bind $f <1> [list focus $f]
  bind $f <Map> [list focus $f]
  bind $f <space> "$f cmd pause"
  bind $f <Return> "$f cmd pt_step 1"
  bind $f <less> "$f cmd pt_step -1"
  bind $f <Right> "$f cmd seek 10"
  bind $f <Left> "$f cmd seek -10"
  bind $f <Down> "$f cmd seek -100"
  bind $f <Up> "$f cmd seek 100"
  bind $f <question> "$f cmd osd_show_progression"
  bind $f 9 "$f cmd volume -1"
  bind $f 0 "$f cmd volume 1"
  set f

aplsimple - 2019-08-17 05:48:51

Probably, you mean

  pack .movieframe -fill both -expand 1

after calling mplayer proc, not?