I have script which execute mplayer command to play audio in crontab. It will be executed in a special time. But this script can not play audio when ncmpcpp ( a front-end for mpd - 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 crontab or script, but get nothing. 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.

link|improve this question
feedback

3 Answers

up vote 1 down vote accepted

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.

link|improve this answer
I have set ao=pulse in ~/.mplayer/config. but set mpd on pulseaudio is so complex. But it this splution is good. – chris Nov 21 '11 at 4:41
feedback

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.

link|improve this answer
It does not help for sound though.. the error from cron for e.g. ogg123 is: ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave ERROR: Cannot open device alsa. – blueyed May 5 at 18:27
feedback

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

export DISPLAY=:0
export XAUTHORITY=/home/YOURUSERNAME/.Xauthority
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.