pgf wrote: 
> 
> So...  my script relies on polling (which doesn't worry me in the
> least), and probably won't cover many corner cases, but it serves my
> purposes.  It relies on the USB audio device coming and going from
> /proc/asound when it's un/plugged.
> 
> The script is invoked as one of the "user commands" on the Tweaks page. 
> The copy here is trimmed from the script I actually run, since mine does
> some other unrelated stuff as well, but I don't think I've introduced
> any new bugs.  It's pretty simple -- hope it might help someone.
> 
> paul (another one)
> 
> > 
Code:
--------------------
  >   > #!/bin/sh
  > 
  > watch_usb_audio()
  > {
  > # loop forever
  > while :
  > do
  > # loop while the device exists
  > while [ -e /proc/asound/$audiodev ]
  > do
  > # if it only just became available...
  > if [ "$prev_usbaudio" != "present" ]
  > then
  > alsactl restore
  > /usr/local/etc/init.d/squeezelite restart
  > fi
  > prev_usbaudio=present
  > sleep 4
  > done
  > 
  > # loop while the device doesn't exist
  > while [ ! -e /proc/asound/$audiodev ]
  > do
  > prev_usbaudio=notpresent
  > sleep 4
  > done
  > done
  > }
  > 
  > audiodev=SoundSticks
  > watch_usb_audio &
  > 
  > exit
  > 
--------------------
> > 

This is indeed a much simpler approach than all this udev stuff, and it
could quite easily be generalised to automatically work with whatever
DAC device is configured in pCP (i.e. to get $audiodev from
/usr/local/etc/pcp/pcp.cfg).  The only downside compared to the udev
approach seems to be that it's polling, as you point out, but a script
that wakes up once every 4 seconds and then runs a few quick commands
will not be a drain on resources. 

You could easily add the same sort of logic as the 'if it only just
became available...' to check whether it 'only just disappeared...' and
then stop Squeezelite accordingly.  And I guess that since it's a user
command, rather than something being run by udev, there may not be the
same issues with the built-in 'kill' not working properly.


------------------------------------------------------------------------
chill's Profile: http://forums.slimdevices.com/member.php?userid=10839
View this thread: http://forums.slimdevices.com/showthread.php?t=113661

_______________________________________________
unix mailing list
unix@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to