Xfce Forum

Sub domains
 

You are not logged in.

#1 2018-05-29 17:22:47

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Playing a test sound while changing volume

Trying to find a way to play a short click sound while changing the volume via GUI in xfce.
I know I can set the keyboard shortcut to increase/decrease the volume by 5% and play the sound each time on keyboard combo.

Just for testing I downloaded a random small wav file http://soundbible.com/1705-Click2.html

Installed "pulseaudio-utils" and tried to do something like this:

#!/bin/bash

PLAY_FILE="/home/misko/Downloads/click2.wav"

x=0
pactl subscribe | grep --line-buffered "sink" | while read -r event type on sync num; do
   ((x++))
   if [[ $x -eq 10 ]]; then
      x=0
      if [[  "$(ps -eo pid,cmd | grep "aplay $PLAY_FILE" | grep -v grep)" == "" ]]; then
         sleep 0.1
         aplay "$PLAY_FILE" 2>/dev/null &
      fi
   fi
 done

It works pretty good with the pnmixer.
That is when changing volume via slider fast, but not while slowly moving the volume control slider.
Sometimes it plays, sometimes not, sometimes double playing. Also noticed that this activates when playing a youtube vdeo in firefox.

Is there a better way to sync playing the "click" with the volume slider?

Last edited by Misko_2083 (2018-05-29 17:30:19)


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

#2 2018-05-30 02:58:08

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,950

Re: Playing a test sound while changing volume

@Misko, your code works well here (with the xfce4-pulseaudio-plugin). I don't get any of those issues that you do.

As for the youtube issue, I was getting the same (looks like youtube plays with the volume as a video loads). I grepped it out and they stopped:

if [[  "$(ps -eo pid,cmd | grep "aplay $PLAY_FILE" | grep -v grep)" == "" 
]]; then
        if [[ "$(wmctrl -l | grep -i youtube)" == "" ]]; then
         sleep 0.1
         aplay "$PLAY_FILE" 2>/dev/null &
        fi
      fi

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2018-05-31 13:55:31

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Playing a test sound while changing volume

@ToZ thanks,
Seems like the pulseaudio plugin works, it's just pnmixer.

ToZ wrote:

As for the youtube issue, I was getting the same (looks like youtube plays with the volume as a video loads). I grepped it out and they stopped:

That will do it. Thanks.


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

Board footer

Powered by FluxBB