Can a python script be made to play an mp3 from crontab

This is the place for queries that don't fit in any of the other categories.

Can a python script be made to play an mp3 from crontab

Postby kyle2k » Sat Feb 01, 2014 3:32 pm

What I am trying to do is have cron run a python script that just plays an mp3 file on my Raspberry Pi running Python 2.7.3.

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 ssh into my headless Pi

Code: Select all
#! /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 when I set cron to run it say every 5 mins it does not work.

Code: Select all
*/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 bit of code such as popen() and call() to no avail.

Could somebody tell me if I heading in the right direction with sub-processes and if so which one I should be looking to use.

Or is this just not possible.

I wanted it to be part of a bigger script that downloads a text file with the song to play from a remote webserver and then plays that song and deletes the file from the server.
I have the other parts working but can not get the song to play because no terminal window is open on the Raspberry Pi.
I have also try with Mplayer and Pygaame.

Thanks for reading Kyle.
Last edited by Mekire on Sat Feb 01, 2014 3:42 pm, edited 1 time in total.
Reason: First post lock.
kyle2k
 
Posts: 2
Joined: Sat Feb 01, 2014 3:19 pm

Re: Can a python script be made to play an mp3 from crontab

Postby kyle2k » Sun Feb 02, 2014 11:45 pm

Stupid newbie mistake :oops:

I hadn't given a /fullpath/to_my/music
kyle2k
 
Posts: 2
Joined: Sat Feb 01, 2014 3:19 pm


Return to General Coding Help

Who is online

Users browsing this forum: W3C [Linkcheck] and 3 guests