A separate point: as a workaround, indeed, an improvement, I tried calling the script that worked before (playing an internet radio stream with mpv) from the Pi's /etc/rc.local, and it doesn't work this way.
In the past, I have called the script by ssh'ing into the Pi, using nohup. I can't see why this should make a difference. But perhaps indeed it does?
Testing shows the script is called, but it doesn't seem to be talking to Alsa (although I added a two-minute delay to allow everything to initialise):
Code: Select all
mimosa[rootfs]$ cat home/pi/playlog
Playing: mms://mediau.yle.fi/liveyleradio1
(+) Audio --aid=1 --alang=eng (wmav2)
File tags:
Title: YleRadio1hires
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
[ao/alsa] Playback open error: No such file or directory
[ao] Failed to initialize audio driver 'alsa'
[ao] This audio driver/device was forced with the --audio-device option.
[ao] Try unsetting it.
Could not open/initialize audio device -> no sound.
Audio: no audio
: 00:00:00 Cache: 0s+16KB
[ffmpeg] Read data packet header failed!
[ffmpeg] Recv other type packet -5
Exiting... (Errors when loading file)
Code: Select all
mimosa[rootfs]$ cat etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# custom
# start yle stream
/home/pi/stream.sh > /home/pi/log &
#/home/pi/stream.sh > /dev/null &
# /custom
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
exit 0
Here is the script itself, altered for debugging:
Code: Select all
mimosa[rootfs]$ cat home/pi/stream.sh
#!/bin/bash
SWITCH='OFF'
PLAYER='mpv '
OPTIONS='--audio-device=alsa/bluealsa --volume=50 '
STREAM='mms://mediau.yle.fi/liveyleradio1 '
# $SPEAKER='1D_AA_D0_C3_79_7C'
sleep 2m #allow Pi to boot if called from startup script
while (sleep 2)
do
if [ `busctl tree org.bluez | wc -l` -lt 5 ] ; then # this tells us the speaker isn't connected, TODO find a better way
echo "The speaker is off"
if [ $SWITCH = 'ON' ] ; then
killall $PLAYER
SWITCH='OFF'
fi
else
if [ $SWITCH = 'OFF' ] ; then
echo "The speaker has just been turned on"
killall $PLAYER
$PLAYER $OPTIONS $STREAM > /home/pi/playlog 2>&1 & #this and the sleep command above are the only alterations
# $PLAYER $OPTIONS $STREAM > /dev/null 2>&1 &
SWITCH='ON'
fi
fi
done