LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to configure flash 9 in firefox to use a specific alsa device (https://www.linuxquestions.org/questions/linux-software-2/how-to-configure-flash-9-in-firefox-to-use-a-specific-alsa-device-629183/)

wastingtime 03-19-2008 08:34 AM

how to configure flash 9 in firefox to use a specific alsa device
 
My machine has a built in sound card and I also use USB headphones.
The machine is set to use ALSA.

I figured how to configure amarok, xine such that when the headphones are plugged in the audio plays through the headphones, and when they are not plugged in it plays through the speakers

However, I can not make firefox + flash 9 play through the headphones - the sound always go to the speakers.

Using audacity I noticed that when I plug the headphones it lists new ALSA device, and also /dev/dsp1 . And indeed by selecting /dev/dsp or /dev/dsp1 I can tell audacity to play either through the speakers or the headphones. When I unplug the headphones, the additional alsa device and /dev/dsp1 disappear.

I found a post that said use aoss (separate package from synaptic) and specify /dev/dsp1. That did not work and after more reading I learned that flash 9 in firefox uses ALSA (where the old flash 7 used OSS so the aoss solution might had worked for it)

So my question is how do I tell flash 9 in firefox to use a specific alsa device.

An alternative would be to swap the order of the ALSA devices so flash 9 finds the headphones first.
Ideally, that would work in such a way that when the headphones are plugged they are the first device, and when not plugged the speakers are.
Or it could use a script that you run to select which device is first (i.e. the default)

pwalden 03-20-2008 01:46 PM

Probably not a good solution, but on my Fedora 7 laptop, if you boot with the USB sound plugged in, it sets up the USB sound as the primary alsa device, while the built in sound is ignored. Thus fash 9 goes to the USB.

wastingtime 03-21-2008 04:52 PM

A solution is create a file .asoundrc in you home directory that specify the default audio device.

Since in my case I want to change the default device to be the USB headphones when they are plugged in and to the builtin speakers when the USB headphones are not plugged in, I created two different .asoundrc files and I swap them as necessary.

You'd need to close programs that hold to the sound device when swapping (e.g. amarok)

1. Plug in your USB audio device and find out the names of the builtin audio, and the USB audio by running in a terminal (kconsole)
Quote:

$ aplay -l
Mine are
card 0: IHC6
card 1: Headset

2. Create two asoundrc files, one for each configuration and place them in you home directory (notice only the last two lines are different)

.asoundrc.builtin
Quote:

pcm.builtin { type hw; card ICH6; }
ctl.builtin { type hw; card ICH6; }

pcm.usb { type hw; card Headset; }
ctl.usb { type hw; card Headset; }

pcm.!default pcm.builtin
ctl.!default ctl.builtin
.asoundrc.usb
Quote:

pcm.builtin { type hw; card ICH6; }
ctl.builtin { type hw; card ICH6; }

pcm.usb { type hw; card Headset; }
ctl.usb { type hw; card Headset; }

pcm.!default pcm.usb
ctl.!default ctl.usb
3. Create a script to detect whether the headphones are plugged in or not and switch files accordingly; place it in your home directory. As explained above I found out that when the headphones are plugged in /dev/dsp1 exists

switch-audio
Quote:

#!/bin/bash
if [ -e /dev/dsp1 ]; then
cp -f ~/.asoundrc.usb .asoundrc
else
cp -f ~/.asoundrc.builtin .asoundrc
fi
Make sure to give it execute permissions
Quote:

$ chmod +x switch-audio
Now after plugging or unplugging the headphones, close amarok, firefox, etc. and run the script. I created a link to it and placed it in the task bar, where I also have links to amarok, firefox etc.

There should also be a way to run the script automatically when the headphones are plugged or unplugged, but I did not bother with that.

wayno 10-19-2008 05:46 AM

Quote:

Originally Posted by wastingtime (Post 3096372)
A solution is create a file .asoundrc in you home directory that specify the default audio device.

Since in my case I want to change the default device to be the USB headphones when they are plugged in and to the builtin speakers when the USB headphones are not plugged in, I created two different .asoundrc files and I swap them as necessary.

You'd need to close programs that hold to the sound device when swapping (e.g. amarok)

1. Plug in your USB audio device and find out the names of the builtin audio, and the USB audio by running in a terminal (kconsole)


Mine are
card 0: IHC6
card 1: Headset

2. Create two asoundrc files, one for each configuration and place them in you home directory (notice only the last two lines are different)

.asoundrc.builtin


.asoundrc.usb


3. Create a script to detect whether the headphones are plugged in or not and switch files accordingly; place it in your home directory. As explained above I found out that when the headphones are plugged in /dev/dsp1 exists

switch-audio


Make sure to give it execute permissions


Now after plugging or unplugging the headphones, close amarok, firefox, etc. and run the script. I created a link to it and placed it in the task bar, where I also have links to amarok, firefox etc.

There should also be a way to run the script automatically when the headphones are plugged or unplugged, but I did not bother with that.

Fantastic!! I've been searching for a solution to this problem for my Fedora 9 laptop and Logitech wireless USB headset. Everyone else is talking about 'asoundconf list' but I don't have and can't find that package. This solution is very simple and worked a treat for me.

Thanks.

Shadow_7 10-21-2008 12:26 PM

There's also a defaults.pcm.card 0 option for .asoundrc

...
defaults.pcm.card 0
...

Where the number represents the card / device as it appears in /proc/asound/cards. The scripted solution might work a little faster than manually editing .asoundrc each time.

Another method since many web browsers default to card 0 is to re-index your alsamodules. One of the only ways to get things like Festival to use a specific card.

#/etc/modprobe.d/alsa_custom
options snd-usb-audio index=0

Or something more like this in full.

#/etc/modprobe.d/alsa_custom START
alias char-major-116 snd
alias char-major-14 soundcore

options snd major=116 cards_limit=3
options snd-usb-audio index=0
options snd-atiixp index=1
options snd-atiixp-modem index=2

alias snd-card-0 snd-usb-audio
alias sound-slot-0 snd-card-0
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss

alias snd-card-1 snd-atiixp
alias sound-slot-1 snd-card-1
alias sound-service-1-0 snd-mixer-oss
alias sound-service-1-1 snd-seq-oss
alias sound-service-1-3 snd-pcm-oss
alias sound-service-1-8 snd-seq-oss
alias sound-service-1-12 snd-pcm-oss

alias snd-card-2 snd-atiixp-modem
alias sound-slot-2 snd-card-2
alias sound-service-2-0 snd-mixer-oss
alias sound-service-2-1 snd-seq-oss
alias sound-service-2-3 snd-pcm-oss
alias sound-service-2-8 snd-seq-oss
alias sound-service-2-12 snd-pcm-oss
#/etc/modprobe.d/alsa_custom END

In conjunction with rebooting, and/or just using /etc/init.d/alsasound stop|start (in debian), it gets the job done. For those troublesome OSS only applications. Like web browsers.

Another option might be to start the app with aoss. Or artsdsp -m or esddsp -m as applicable.

darthaxul 10-19-2010 08:01 PM

asoundrc worked
 
pcm.usb {type hw; card Headset;}
ctl.usb {type hw; card Headset;}
pcm.!default pcm.usb
ctl.!default ctl.usb

gods, i was searching forever for this...


All times are GMT -5. The time now is 02:55 PM.