I don’t really know the answer. But I think it has to do with sound devices. They are “owned” – assigned to the user logged in at the console or main GUI session.
As far as I know, it has always been thus. The sound doesn’t work for other users. Or, at least, I have never succeeded with that.
I am just trying to run the bash script as username at system startup. I have put another bash script in rc3.d which has the line with “su - …” but it won’t play. It seems to me not a good idea to run mplayer as root because I also want to be able to stop it later as a username. So I hope someone who knows to explain.
nrickert is correct, I believe. Also, does every user have the audio.mp3 file in their /home/* subdirectory?
Lastly, why would you want to run mplayer as root? Is it somehow critical for your setup? If that’s the case, we might be able to work out a different solution :).
Leaving the (IMHO most) important question (“Why?”) aside, firstly there is this:
-cache 30000000
erm
-cache <kBytes>
This option specifies how much memory (in **kBytes**) to use when precaching a file or URL.
Especially useful on slow media.
30 Gigabytes of cache for an audio file? Interesting.
And secondly a short look into the crystal ball.
pulseaudio running
and running as $NORMAL_USER?
and blocking audio device for all other users (including root)?
whoami
axel
pulseaudio --start
su - c "mplayer -ao pulse /usr/share/sounds/alsa/test.wav"
support. You will not be able to use your remote control.
Playing /usr/share/sounds/alsa/test.wav.
libavformat version 57.56.101 (external)
Audio only file format detected.
Load subtitles in /usr/share/sounds/alsa/
==========================================================================
Trying to force audio codec driver family libmad...
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 2 ch, s16le, 1411.2 kbit/100.00% (ratio: 176400->176400)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
Whops …
Fun fact, after some time it might work (if pulseaudio “releases” its lock on the audio device and alsa could be used directly).
No. It is not necessary. It must be played only as one particular user.
Lastly, why would you want to run mplayer as root? Is it somehow critical for your setup? If that’s the case, we might be able to work out a different solution :).