I have a bash script that plays .mp3 files on my Raspberry Pi via omxplayer. But can not control the local (earphone) audio volume with the GUI. Is there a command for the CLI that I can implement in the bash script? I have searched quite a bit, but can not find such a command.
Code:
omxplayer Song_Title.mp3
Set audio for local (earphone) output:
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 1
omxplayer -o local
Thanks!
to provide more precise information for playing through scripts, there are 3 ways to change sound volume in current version of omxplayer, and values are not so intuitive:
--vol YYY
, double millibels, default 0, range [-6000:0]double:XXX
, default 1, range [0:1]xxx to yyy relation is: XXX = 10 ^ (YYY / 2000)
... according to omxplayer.cpp source code, reverse formula would be: YYY = 2000 * (log XXX)
.
so if we need:
(10^(-4000/2000)=10^-2=0.01
(10^(-2000/2000)=10^-1=0.1
(10^(-602/2000))~=0.5
(10^(0/2000)=10^0=1)
working bash script for dbus volume command:
export DBUS_SESSION_BUS_ADDRESS=$(cat /tmp/omxplayerdbus.${USER:-root})
dbus-send --print-reply --session --reply-timeout=500 \
--dest=org.mpris.MediaPlayer2.omxplayer \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set \
string:"org.mpris.MediaPlayer2.Player" \
string:"Volume" double:0.5 # <-- XXX=0.5 (50% sound volume)
equals to volume parameter at startup:
omxplayer --vol -602 mediaFileName.mp4
... both sets sound volume to 50%.