chiark / gitweb /
bin/disorder-notify: Rewrite and take over the functionality of `media-keys'.
[profile] / bin / play-rawk
CommitLineData
5f9b345a
MW
1#! /usr/bin/wish
2
3package require Tclx
4
3bee9f27 5set STREAM "https://rawk.distorted.org.uk/rawk"
5f9b345a
MW
6catch { source $env(HOME)/.play-rawk }
7
8set CMD [list \
9 gst-launch-1.0 uridecodebin uri=$STREAM ! \
10 pulsesink client-name=play-rawk]
11
12set kidstat -
13set playing false
14set status "\[Not started]"
15
16proc update-status {} {
17 global kidstat playing status
18 set r [gets $kidstat line]
19 if {$r >= 0} {
20 set status $line
21 } elseif {[eof $kidstat]} {
22 close $kidstat
23 set playing false
24 .play configure -text "Play"
25 set status "\[Stopped]"
26 }
27}
28
29proc infanticide {} {
30 global playing kidstat
31
32 if {$playing} { catch { kill [pid $kidstat] } }
33}
34
35proc toggle-playing {} {
36 global CMD playing kidstat
37
38 if {$playing} {
39 infanticide
40 } else {
41 set kidstat [open "|$CMD 2>@1"]
42 fconfigure $kidstat -blocking false -buffering line
43 fileevent $kidstat readable update-status
44 .play configure -text "Stop"
45 set playing true
46 }
47}
48
49proc byebye {} {
50 infanticide
51 exit 0
52}
53
54button .play \
55 -text "Play" \
56 -command "toggle-playing"
57entry .status \
58 -state readonly \
59 -width 48 \
60 -textvariable status
61pack .play -side left -padx 2 -pady 2
62pack .status -side left -padx 2 -pady 2 -fill x -expand true
63bind . "q" { byebye }
64bind . "z" { wm iconify . }
65bind . <space> { .play invoke }
66##bind . <KeyPress> { puts "key <%K>" }
67wm protocol . "WM_DELETE_WINDOW" { byebye }