5

I have set up a script, which executes an mplayer command, in order to play audio in crontab. It will be executed in a special set time, but this script can not play audio when ncmpcpp (a front-end for mpd, aka. Music Player Daemon) is playing music. But this script can play audio when I execute it from terminal like this:

sh bin/alarm.sh   

I try to get output from either crontab or script, but to no avail. I guess some setting in ncmpcpp or mplayer is wrong, or mpd is using same daemon with crontab's daemon.

  • Anyway, I can not find out the solution. If you know, please help me.
v2r
  • 9,707

4 Answers4

3

The problem seems to be that mpd runs under user mpd per default (as a system daemon) and is thus unable to join your sessions' pulseaudio mixer, therefore it hogs the sound card output via alsa or even oss. In my answer, I assume that you are logged in and that the crontab is yours and not the system crontab.

MPD

Depending on your priorities, you have a lot of options that mostly circle around the idea teaching mpd to not hog the sound and use pulseaudio instead. See the mpd wiki.

mplayer

You can configure mplayer to default to pulseaudio by placing a line ao=pulse in ~/.mplayer/config but pulseaudio should pick it up nicely with its alsa plugin.

aquaherd
  • 6,345
0

When using e.g. play (from the sox package), the following information needs to be exported:

export DISPLAY=:0
export XAUTHORITY=/home/YOURUSERNAME/.Xauthority
blueyed
  • 9,125
0

In your crontab, please add this to the command section

export DISPLAY=:0.0 && sh /bin/alarm.sh

The export DISPLAY=:0.0 is required to run Graphical apps.

0
XDG_RUNTIME_DIR=/run/user/$(id -u) <sound command>

Also have a look at the links below, as other vars might be needed:

https://wiki.archlinux.org/index.php/PulseAudio#Play_sound_from_a_non-interactive_shell_.28systemd_service.2C_cron.29

mplayer can't play audio from cron while ncmpcpp is playing simultaneously

Zanna
  • 72,312