Talk:ALSA

From ArmadeusWiki
Jump to: navigation, search

Use audio devices as non-root user

  1. Create a group that will get permission on the audio device
  2. Add the non-root user to this group.
  3. Give permission to this group at boot time.

To do this, run the following command as root on your APF. Don't forget to adjust the u and g variables!

Warning Warning: If you already have a script loading the ALSA module at boot time and called S60alsa, it will be overwritten by this script.


u=guest      # the non-root username
g=audio      # the group that will get permissions on the resources

# Create the new group:
addgroup $g

# Add the non-root user to the group:
l=`grep $g /etc/group`
ug=`echo $l | awk -F : '{print $4}'`
sed "
/$l/ c\
$l`! [ $ug ] || echo ,`$u
" /etc/group > /etc/group.tmp
mv /etc/group.tmp /etc/group

# Give permission to the group at boot time:
cat <<eof >/etc/init.d/S60alsa
#!/bin/sh
# The spi_imx module does not seem to be required by the ALSA one.
modprobe snd-imx-alsa-tsc2102
# wait for the creation of all nodes
sleep 2
# give permissions of the sound device to the audio group
chown root:audio /dev/snd/*
eof

chmod a+x /etc/init.d/S60alsa

After reboot, you should be able to play audio files as guest user.