python - Raspberry Pi and Mplayer sound loop error -


i'm trying play 1sec sound in loop using mplayer. when run code crashes raspberry os. noticed times multiple instances of mplayer processes hanging in task manager i've added code process id pidof , kill it.
process keep appearing multiple times, , raspberry keeps crashing after loops.

also, times seems sound overlapped (probably because of multiple instances of 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 signal arduino      = os.popen('pidof mplayer').read()     if(a != ''):         os.system('sudo kill ' + str(a)) 

note: i've tried use other players, mpg123, problem same.

if sound file time longer sleep time of 1.5 seconds, natural endless number of processes builts up, because running mplayer in background, can seen trailing '&'.

killing processes bit of hack. , introduces problem, open file-like object os.popen() never close.

rather should trim sound file length want have play , remove '&' @ end of command line. alternative trimming sound file may find option of mplayer limiting time plays tune.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -