JABpi
Posts: 22
Joined: Wed Feb 06, 2013 3:44 am

crontab script resources

Thu Feb 14, 2013 4:58 am

I was not sure about selecting the right subject for this post...

I executed "nano /bin/play-radio"
in this file I have one line:
mplayer -cache 1024 --af=volume=0:1, --af=pan=1:0.5:0.5 [stream URL]

then I did "chmod -x /bin/play-radio" to make it executable.

And from "crontab -e" I added "@reboot play-radio"

When the Pi boots it streams on its own but the sound cuts off often like maybe every 10 to 20 seconds.

Where I am confused is if I rem out the @reboot in the crontab and I login via ssh and I run that same line to execute mplayer it runs nonstop with no cuts for days.

Why does it cut off when ran from the crontab and how can I fix this?

Thanks.

xian
Posts: 51
Joined: Thu Nov 01, 2012 8:42 pm

Re: crontab script resources

Thu Feb 14, 2013 4:10 pm

I have found that mplayer crashes out sometimes with problems to do with playing the sound (possibly audio driver related, I haven't looked into it), and it seems more likely to happen when my system is under heavy load. A fairly brutal way I keep my audio going is with a loop in my script:

Code: Select all

while :
do
    mplayer <options to play internet radio>
done

JABpi
Posts: 22
Joined: Wed Feb 06, 2013 3:44 am

Re: crontab script resources

Thu Feb 14, 2013 7:00 pm

I don't think this is the issue I am having as mplayer does not stop playing, it just cuts off for one or two seconds and then it continues and this happens every 10 to 20 seconds.
It does seam obvious it probably does this because the Pi can't keep up with the demand.

My confusion is why it is working well when I run the command manually and cutting when I run it through the script?

xian
Posts: 51
Joined: Thu Nov 01, 2012 8:42 pm

Re: crontab script resources

Fri Feb 15, 2013 10:59 pm

Sorry, I miss understood. Yes mine does cut out for a few seconds every now and then and that is definitely linked the RPi being under load. I believe the Linux scheduler does not treat all processes equally, and tries to give processes that have user interaction a higher priority.

You could try executing mplayer with a higher priority (lower nice number) e.g.

Code: Select all

nice -n -10 mplayer ...
Also see

Code: Select all

man nice
for more details. A process must have privileges to be able to get higher priority, so you may need to investigate calling it from the system crontab, or various incantations of sudo and su.

JABpi
Posts: 22
Joined: Wed Feb 06, 2013 3:44 am

Re: crontab script resources

Sat Feb 16, 2013 5:17 am

unfortunately it makes no difference.
I tried also nice -n -19 mplayer...
When it is streaming, as soon as I see the activity LED the sound cuts off.
If I run the script manually there is no cut off even when the activity LED goes on.

Is there another way to start a script then from a cron job?

Return to “General discussion”