diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-07-12 14:11:39 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-07-12 14:11:39 +0800 |
| commit | aac617d7178874a65c0deca28897df7fd2c3620b (patch) | |
| tree | db30375db7975d116e2ba738eaa23c0364add371 | |
| parent | 5bc975391c78fc7e41f39d1fca0d36624a6634b6 (diff) | |
pulsemixer -> playerctl. using more smooth transition
| -rwxr-xr-x | audio-autoAdjust.sh | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/audio-autoAdjust.sh b/audio-autoAdjust.sh index 370ab0e..75fa921 100755 --- a/audio-autoAdjust.sh +++ b/audio-autoAdjust.sh @@ -8,23 +8,21 @@ VOL=0 STATE=1 # usr-def vars -OTHERPLAYER_MUSIC_PERCENTAGE=35 -NORMAL_MUSIC_PLAYER_PERCENTAGE=50 - -function getMusicId() { - pulsemixer --list-sink | grep 'Name: spotify' | awk '{print $4}' | sed 's/,$//' -} - -function getVideoId() { - pulsemixer --list-sink | grep 'Name: Chromium' | awk '{print $4}' | sed 's/,$//' -} +OTHERPLAYER_MUSIC_PERCENTAGE=45 +NORMAL_MUSIC_PLAYER_PERCENTAGE=60 function lower_music() { - pulsemixer --id "$(getMusicId)" --set-volume $OTHERPLAYER_MUSIC_PERCENTAGE + for ((i=$NORMAL_MUSIC_PLAYER_PERCENTAGE; i>=$OTHERPLAYER_MUSIC_PERCENTAGE; i--)); do + playerctl -p spotify volume 0.$i + sleep 0.01 + done } function normal_music() { - pulsemixer --id "$(getMusicId)" --set-volume $NORMAL_MUSIC_PLAYER_PERCENTAGE + for ((i=$OTHERPLAYER_MUSIC_PERCENTAGE; i<=$NORMAL_MUSIC_PLAYER_PERCENTAGE; i++)); do + playerctl -p spotify volume 0.$i + sleep 0.01 + done } if [ "$1" ]; then @@ -34,13 +32,13 @@ if [ "$1" ]; then elif [[ "$1" == '--daemon' || "$1" == '-d' ]]; then while true; do if [[ "$(systemctl is-system-running)" == "running" || "$(systemctl is-system-running)" == "degraded" ]]; then - if [ $(getVideoId) ]; then + if [[ $(playerctl status -p chromium) == "Playing" ]]; then if [ $STATE -eq 0 ]; then STATE=1 echo VideoDetected lower_music fi - elif [ $(getMusicId) ] && [ $STATE -eq 1 ]; then + elif [[ $(playerctl status -p spotify) == "Playing" ]] && [ $STATE -eq 1 ]; then STATE=0 echo VideoGone normal_music |
