How to tell Firefox to use another ALSA device

alsaaudiobrowserfirefox

I have an onboard sound card, and also a connected bluetooth headset. I have configured the bluetooth device in /etc/asound.conf:

# cat /etc/asound.conf

pcm.bluetooth {
    type bluetooth
    device 12:34:56:78:9a:bc
    profile "auto"
}

ctl.bluetooth {
    type bluetooth
}

By default, the onboard card is used for all sound (apparently, the default onboard card does not even need to be listed in asound.conf)

When I want an application to use my bluetooth alsa device, I have to specify it, such as:

mplayer -ao alsa:device=bluetooth file.mp3

That's fine for me. But I need a way to tell my browsers to use bluetooth alsa device as well.

I have found a way how to start chromium using the --alsa-output-device commandline option:

chromium --alsa-output-device=bluetooth

I need a similar way to start firefox, but I could not find any.

How can I tell firefox to use my bluetooth alsa device, without having to modify /etc/asound.conf or ~/.asoundrc every time ?

UPDATE:

I have followed @lgeorget's advice and my /etc/asound.conf now looks like this:

pcm.!default {
type plug
slave.pcm {
        @func getenv
        vars [ ALSAPCM ]
        default "hw:0,0"
    }
}

pcm.bluetooth {
    type bluetooth
    device 12:34:56:78:9a:bc
    profile "auto"
}

ctl.bluetooth {
    type bluetooth
}

When I start firefox using ALSAPCM=bluetooth firefox, I do get sound in my bluetooth headset, but firefox runs at 100% CPU (on my 4 cores) and the youtube video plays at 10x speed (and the sound is correspondingly (garbled). I don't understand what's happening. When I start firefox without ALSAPCM=bluetooth, everything is OK, and sound plays on default alsa device.

Best Answer

Apparently there is no option for firefox, but you can manipulate the ALSA output through environment variables.

Try for example:

ALSA_PCM_CARD=bluetooth firefox

Alternatively, if this does not work, try scripting a little your .asoundrc

pcm.!default {
type plug
slave.pcm {
        @func getenv
        vars [ ALSAPCM ]
        default "hw:hdmi"
    }
}

(replace "hw:hdmi" with your normal pcm). Then if you want a program to use a specific PCM, use:

ALSAPCM=bluetooth firefox

Sources:

Related Question