mplayer slave: set volume before starting the playback

leemes picture leemes · Jan 21, 2013 · Viewed 10.7k times · Source

I know this is about a specific program (mplayer back-end); however it will be used to program a front-end so I hope it is still considered on-topic on Stack Overflow.

I want to run two mplayer slave instances which will be used to fade between different audio streams (webradio; smoothly change the channel). To do this, I set the "software volume" of mplayer so it will not affect the PCM output channel of the sound card but insert a software volume mixer to adjust the volume.

However, I encounter the following problem.

I start mplayer with the following command (can be tested on command-line):

mplayer -slave -idle -softvol

and send the following commands to mplayer:

loadfile <url>
set volume 0

it starts (for a short time) to play the file at 100% volume and then jumps to 0% volume. If I swap the two commands, mplayer tells me that I can't adjust the volume:

Failed to set property 'volume' to '0'.
ANS_ERROR=PROPERTY_UNAVAILABLE

Obviously, the audio filter isn't yet loaded / audio output not yet set up or something like that, so mplayer can't change the volume of a non-existing audio output.

Can I force mplayer to initialize everything in advance so that I can set the volume to 0%, load the file and then increase the volume to fade in the playback?

I already checked whether I can set the volume after playing some file (e.g. a silent dummy file); mplayer complains with the same error. For now, the only option I can think of is to start such a dummy file, adjust the volume, stop the dummy file, load the correct file to be played, and it will start with the volume just set. But I can't believe this is the best option.

Answer

leemes picture leemes · Jan 21, 2013

I solved the problem by myself: While I tried to follow this guide, -af volume=0 didn't help. However, there also is a -volume 0 command line option which worked for me:

mplayer -slave -idle -softvol -volume 0