Skip to content

Instantly share code, notes, and snippets.

@crsantos
Created October 22, 2014 20:23
Show Gist options
  • Save crsantos/206b9646ad1f0551edec to your computer and use it in GitHub Desktop.
Save crsantos/206b9646ad1f0551edec to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import subprocess, sys, threading
PLAY_COMMAND = "mpg123"
class PlayerThread(threading.Thread):
def __init__(self, filename):
self.filename = filename
threading.Thread.__init__(self)
def run(self):
try:
retcode = subprocess.call(PLAY_COMMAND +" " + self.filename, shell=True)
if retcode < 0:
print >> sys.stderr, "Child was terminated by signal", -retcode
else:
print >> sys.stderr, "Child returned", retcode
except OSError as e:
print >> sys.stderr, "Execution failed:", e
def play(filename = None):
""" Play a filename using the mpg123 system lib """
if not filename:
print "You should provide a valid filename"
return
def main():
thread = PlayerThread("./media/creakingdoor.mp3")
thread.start()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment