I'm trying to play a 1sec sound in loop using mplayer
. When I run the code it crashes the raspberry os. I noticed that some times multiple instances of the mplayer
processes were hanging in the task manager so I've added code to get the process id pidof
and kill
it.
But the process keep appearing multiple times, and raspberry keeps crashing after some loops.
Also, some times it seems the sound is overlapped (probably because of the multiple instances of the process)
import os
import time
import serial
# arduino stuff
ser = serial.Serial('/dev/ttyACM0', 9600)
while True:
os.system('mplayer -really-quiet /home/pi/Desktop/sound.mp3 &')
time.sleep(1.5)
ser.write('1') # send a signal to arduino
a = os.popen('pidof mplayer').read()
if(a != ''):
os.system('sudo kill ' + str(a))
Note: I've tried to use other players, like mpg123
, but the problem is exactly the same.