summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-07-07 16:14:26 -0500
committerCase Duckworth2022-07-07 16:14:26 -0500
commitbddd5d55b018f47b3b8387b53e7664346fda2497 (patch)
tree909b81a7c39a749f91dfa3e76cca4380ecc6b2de
parentMove main to the top (diff)
downloadradio-bddd5d55b018f47b3b8387b53e7664346fda2497.tar.gz
radio-bddd5d55b018f47b3b8387b53e7664346fda2497.zip
Kill playing radio before playing another
-rwxr-xr-xradio15
1 files changed, 12 insertions, 3 deletions
diff --git a/radio b/radio index ba317b4..3c1fdda 100755 --- a/radio +++ b/radio
@@ -101,21 +101,30 @@ _radio_play() {
101 else 101 else
102 station="$candidates" 102 station="$candidates"
103 fi 103 fi
104
105 if [ -f "$RADIO_PID_FILE" ]; then
106 _radio_kill_impl
107 fi
108
104 echo >&2 "Playing $(echo "$station" | cut -f $_radio_desc)..." 109 echo >&2 "Playing $(echo "$station" | cut -f $_radio_desc)..."
105 "$RADIO_PLAYER" "$(echo "$station" | cut -f $_radio_url)" >"$RADIO_STATUS_FILE" 2>&1 & 110 "$RADIO_PLAYER" "$(echo "$station" | cut -f $_radio_url)" >"$RADIO_STATUS_FILE" 2>&1 &
106 echo $! >"$RADIO_PID_FILE" 111 echo $! >"$RADIO_PID_FILE"
107 exit 112 exit
108} 113}
109 114
115_radio_kill_impl() {
116 while xargs -a "$RADIO_PID_FILE" kill 2>/dev/null; do
117 printf '.'
118 done
119}
120
110_radio_kill() { 121_radio_kill() {
111 if ! [ -f "$RADIO_PID_FILE" ]; then 122 if ! [ -f "$RADIO_PID_FILE" ]; then
112 echo >&2 "I don't think radio is running." 123 echo >&2 "I don't think radio is running."
113 exit 1 124 exit 1
114 fi 125 fi
115 printf >&2 '%s' "Killing radio" 126 printf >&2 '%s' "Killing radio"
116 while xargs -a "$RADIO_PID_FILE" kill 2>/dev/null; do 127 _radio_kill_impl
117 printf '.'
118 done
119 rm "$RADIO_PID_FILE" 128 rm "$RADIO_PID_FILE"
120 echo 129 echo
121 exit 130 exit