Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-12-29 15:28:32 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-12-29 15:28:32 (GMT)
commitc70d113ece298c8e649021285419e27084d19e0f (patch)
tree0424d6f8748411cbbd3adb82b94ed6db84f4dce6
parent54cde28279a16df5f6de37ad3daef65281bbd7f7 (diff)
check for gst-launch in multiple places
-rw-r--r--utils/play_audio.py52
1 files changed, 49 insertions, 3 deletions
diff --git a/utils/play_audio.py b/utils/play_audio.py
index 2ed445b..124fae6 100644
--- a/utils/play_audio.py
+++ b/utils/play_audio.py
@@ -22,13 +22,59 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
-
+import os
import subprocess
+import logging
+_logger = logging.getLogger('lettermatch-activity')
+
+
+GST_PATHS = ['/usr/bin/gst-launch', '/bin/gst-launch',
+ '/usr/local/bin/gst-launch',
+ '/usr/bin/gst-launch-1.0', '/bin/gst-launch-1.0',
+ '/usr/local/bin/gst-launch-1.0',
+ '/usr/bin/gst-launch-0.10', '/bin/gst-launch-0.10',
+ '/usr/local/bin/gst-launch-0.10']
+
+
def play_audio_from_file(parent, file_path):
""" Audio media """
- command_line = ['gst-launch', 'filesrc', 'location=' + file_path,
+
+ gstlaunch = None
+ for path in GST_PATHS:
+ if os.path.exists(path):
+ gstlaunch = path
+ break
+
+ if gstlaunch is None:
+ _logger.debug('gst-launch not found')
+ return
+
+ command_line = [gstlaunch, 'filesrc', 'location=' + file_path,
'! oggdemux', '! vorbisdec', '! audioconvert',
'! alsasink']
- subprocess.call(command_line)
+ check_output(command_line, 'unable to play audio %s' % (file_path))
+
+
+def check_output(command, warning):
+ ''' Workaround for old systems without subprocess.check_output'''
+ if hasattr(subprocess, 'check_output'):
+ try:
+ output = subprocess.check_output(command)
+ except subprocess.CalledProcessError:
+ log.warning(warning)
+ return None
+ else:
+ import commands
+
+ cmd = ''
+ for c in command:
+ cmd += c
+ cmd += ' '
+ (status, output) = commands.getstatusoutput(cmd)
+ if status != 0:
+ _logger.warning(warning)
+ return None
+ return output
+