I am trying to have cron run a python script that plays an MP3 file.
It sounded easy but I have been searching and struggling to find the correct solution and was hoping someone could steer me in the right direction.
This code below works fine when I connect via SSH into my headless Raspberry Pi:
#! /usr/bin/env python
# play mp3 from cron task
# Import moduals and functions
import os, sys
os.system('omxplayer -o local Lithium.mp3')
sys.exit()
But it does not work when cron is set to run every 5 minutes.
*/5 * * * * python /home/pi/music/mp3.py &>/dev/null
After searching around I seem to think it should be run as some sort of sub-process?
I have tried various bits of code such as popen()
and call()
to no avail.
Am I heading in the right direction with sub-processes and if so which one I should be looking to use, or is this not possible.
omxplayer /full/path/to/video> /dev/null 2>/dev/null &