2017-03-10 00:00:54 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
import winsound
|
|
|
|
|
|
|
|
def connect_plugin(sound_file):
|
|
|
|
winsound.PlaySound(sound_file, winsound.SND_FILENAME)
|
|
|
|
except ImportError:
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
play_cmd = {}
|
|
|
|
|
2017-03-11 12:33:51 +01:00
|
|
|
def _subprocess(*args):
|
|
|
|
FNULL = open(os.devnull, 'wb')
|
|
|
|
subprocess.call(
|
|
|
|
args, stdout=FNULL, stderr=subprocess.STDOUT, close_fds=True)
|
|
|
|
|
2017-03-10 00:00:54 +01:00
|
|
|
def connect_plugin(sound_file):
|
|
|
|
global play_cmd
|
|
|
|
|
|
|
|
ext = os.path.splitext(sound_file)[-1]
|
|
|
|
try:
|
2017-03-11 12:33:51 +01:00
|
|
|
return _subprocess(play_cmd[ext], sound_file)
|
2017-03-10 00:00:54 +01:00
|
|
|
except (KeyError, AttributeError):
|
|
|
|
pass
|
|
|
|
|
2017-03-10 17:34:31 +01:00
|
|
|
programs = ['gst123', 'gst-play-1.0']
|
2017-03-10 00:00:54 +01:00
|
|
|
if ext == '.wav':
|
|
|
|
programs.append('aplay')
|
|
|
|
elif ext == '.mp3':
|
|
|
|
programs += ['mpg123', 'mpg321', 'mpg321-mpg123']
|
|
|
|
for cmd in programs:
|
|
|
|
try:
|
2017-03-11 12:33:51 +01:00
|
|
|
_subprocess(cmd, sound_file)
|
2017-03-10 00:00:54 +01:00
|
|
|
except OSError:
|
|
|
|
pass # log here!
|
|
|
|
else:
|
|
|
|
play_cmd[ext] = cmd
|
|
|
|
break
|