diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2016-01-11 20:54:46 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2016-01-11 20:54:46 +0100 |
| commit | 90044a0452c64d599f97a4881678a421f3dd357d (patch) | |
| tree | b4d9137e8ea3dbcfc1b975f3257029cde7fb45cb /scripts/media_control.sh | |
| parent | 6d2a88231a0257e8f21b29022f0b69c8a8f2231b (diff) | |
| download | dotfiles-90044a0452c64d599f97a4881678a421f3dd357d.tar.gz dotfiles-90044a0452c64d599f97a4881678a421f3dd357d.zip | |
rework media_control to work with pulseaudio
1) outsource check if spotify is playing in media_is_spotify_playing.sh
2) use media_is_spotify_playing in media_status.sh
3) rework media_control using media_is_spotify_playing.sh
Diffstat (limited to 'scripts/media_control.sh')
| -rwxr-xr-x | scripts/media_control.sh | 74 |
1 files changed, 66 insertions, 8 deletions
diff --git a/scripts/media_control.sh b/scripts/media_control.sh index f2e6612..b158586 100755 --- a/scripts/media_control.sh +++ b/scripts/media_control.sh @@ -4,6 +4,11 @@ # NOTE: # if spotify is running toggle is consumed by spotify. + +function spotify_send_command { + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$1 +} + # arg parsing if [ "$1" = "toggle" ] then @@ -18,20 +23,73 @@ fi if [ "$spotify_cmd" != "" ] then - # can't be sure if spotify was running and should play again - if [ "$spotify_cmd" = "PlayPause" ] + # check if spotify and mpd are running + if pgrep spotify &>/dev/null then - if [ "$(ps -A | grep spotify)" != "" ] + spotify_running=true + else + spotify_running=false + fi + + if pgrep mpd &>/dev/null + then + mpd_running=true + if type mpc &>/dev/null then - dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$spotify_cmd + mpd_controllable=true else + mpd_controllable=false + fi + else + mpd_running=false + fi + + # both are running -> decide who gets the command + # the playing program gets the commands + if $spotify_running && $mpd_running + then + if ! $mpd_controllable + then + spotify_send_command $spotify_cmd + >&2 echo "mpd is running put mpc is not available to control it!" + exit + fi + + spotify_playing=$(./media_is_spotify_playing.sh) + if $(mpc | grep "\[playing\]") + then + mpd_playing=true + else + mpd_playing=false + fi + + if $spotify_playing && $mpd_playing + then + >&2 echo "mpd and spotify are playing!" + elif $spotify_playing + then + spotify_send_command $spotify_cmd + elif $mpd_playing + then mpc $1 + # nothing is actually running + # don't know who was playing -> send spotify all commands + else + spotify_send_command $spotify_cmd fi - elif [ "$(lsof | grep /dev/snd | grep spotify)" != "" ] + + # only spotify is running + elif $spotify_running then - dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$spotify_cmd - elif [ "$(mpc | grep '\[' | cut -f1 -d' ')" != "" ] + spotify_send_command $spotify_cmd + # only mpd is running + elif $mpd_running then - mpc $1 &>/dev/null + if $mpd_controllable + then + mpc $1 + else + >&2 echo "mpd is running put mpc is not available to control it!" + fi fi fi |
