Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.
share|improve this question
add comment

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.

share|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. –  NagatoPain Nov 21 '11 at 4:41
add comment

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.

share|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 '12 at 18:27
add comment

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

export DISPLAY=:0
export XAUTHORITY=/home/YOURUSERNAME/.Xauthority
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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