two sound files at the same time - problem with crontab

Asked by Rosika Schreck

Info:
My system: Linux Lubuntu 20.04.2 LTS, 64 bit

Hi altogether,

I have Big-Ben chimes played out every quarter of an hour and put the respective entries in my crontab.
Example:

15 * * * * if [ ! -f /tmp/Ruhe ]; then mplayer /media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/DATEN-PARTITION/Dokumente/Pausenzeichen/Big_Ben_chimes/Big_Ben_quarter_hour > /dev/null 2>&1; fi

That works very well. But I run into problems if I have some other noise (sound-file) played out at the same time.

Background:

I can´t stand complete silence and thus need some sort of background noise on a permanent basis.

As a rule I run this command:

firejail mpv --loop=inf /media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/DATEN-PARTITION/Musik/sounds_von_anoise/sounds/coffee_shop.ogg
from within a terminal.

which plays some coffee-shop background noise in a permanent loop.
This works well too.

However: when running the mpv-command for background noise I don´t get the chimes any more...
... which is weird as they are played back when issuing the respective command from within a terminal.

So, the command

firejail mplayer /media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/DATEN-PARTITION/Dokumente/Pausenzeichen/Big_Ben_chimes/Big_Ben_quarter_hour

works even if "coffee-shop" is running at the same time.
But it doesn´t work whenever it´s started by crontab!

BTW: the fact that I run the command within the sandbox "firejail" is of no consequence whatsoever.
The result is the same when issuing the command outside the sandbox.

Does anybody have a clue why that "problem" exists?

Many thanks in advance.

Greetings
Rosika

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu cron Edit question
Assignee:
No assignee Edit question
Solved by:
Rosika Schreck
Solved:
Last query:
Last reply:
Revision history for this message
Wim (launchpad-xs4all) said :
#1

Rosika,

i do not know what is causing this problem.
But i have a suggestion to make a work-around:

Create a sound-file of 14min 59 sec. long,
starting with the Big_Ben_chimes/Big_Ben_quarter_hour,
directly followed by Coffee-Shop-Noise.

Then every 15 minutes the Big Ben sounds,
and the rest of the 14min49 you are in a Coffee-Shop (at least, qua sound)

Perhaps you can do this,
until the real solution is given by someone else.

Revision history for this message
Rosika Schreck (rosika) said :
#2

Hi Wim,

thanks so much for suggesting that workaround. It´s highly appreciated.

I may inform you that I got it sorted out in the meantime.

With the help of some kind people from the itsfoss community and from the MPlayer-users mailing list I could solve the problem.

I quote Alexander Strasser here:

    You can’t easily just share one sound hardware with many users. So
    there is software on top that allows you to do this. E.g pulse audio
    is one such solution.

    […] I infer, that when all the processes use pulse audio
    for output it works for you. When your mplayer is started by cron,
    it can’t connect to pulse audio for some reason. Then it tries to use
    alsa which fails because it can’t get the audio device for itself.

See https://itsfoss.community/t/two-sound-files-at-the-same-time-problem-with-crontab/6805/14 for the discussion.

This seems to have been the problem.

I changed my crontab-enrtries thus (example):

15 * * * * if [ ! -f /tmp/Ruhe ]; then XDG_RUNTIME_DIR="/run/user/1000" mplayer /media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/DATEN-PARTITION/Dokumente/Pausenzeichen/Big_Ben_chimes/Big_Ben_quarter_hour > /dev/null 2>&1; fi

So basically prepending the environment variable XDG_RUNTIME_DIR="/run/user/1000" to the mplayer command did the trick.
That way the Big-Ben chimes get played back even if the coffee-house loop is already running. Both audio files are played back at the same time.

Many thanks, Wim, for your help.
Many greetings and keep safe

Rosika