2

I'm running MPD (Music Player Daemon) on a Raspperry Pi, connected to a somewhat high-power audio amplifier. The amplifier gets quite hot if left on 24/7 and I'm worried about it burning itself out, not to mention the quiet AC hum that bleeds through into the speakers, but I don't like having to walk over to it to turn it on and off every time I want to listen to music.

I've noticed that MPD automatically automatically opens and closes its connection to PulseAudio when it starts and stops playing music, rather than leave the connection open all the time as most programs do. I've hooked up a power relay between the amplifier and its power outlet connected to one of the Pi's GPIO pins, and I'm wondering if there's a way that I can get a shell script or something to run to toggle that pin on and off automatically in accordance with when MPD has the audio device open (or, if I did this at the ALSA level instead of the PulseAudio level, when any application has the audio device open).

Is this possible, or would I be better off modifying and recompiling MPD to run the shell script itself?

1 Answer 1

2

This is a shell script I came up with when trying to execute a code when something opens the microphone, you might be able to adapt it to your needs. The key is pactl subscribe:

#!/bin/bash

source_number=""

pactl subscribe | while read x event y type num; do
    if [ $event == "'new'" -a $type == 'source-output' ]; then
        source_number=$num
        notify-send -u normal -a "Microphone Monitor" "Microphone ON" "Microphone has been turned ON"
        echo "$(date -Is) Microphone on"
    fi

    if [ $event == "'remove'" -a $type == 'source-output' -a $num == "$source_number" ]; then
        source_number=""
        notify-send -u normal -a "Microphone Monitor" "Microphone OFF" "Microphone has been turned OFF"
        echo "$(date -Is) Microphone off"
    fi
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .