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 16:05:21 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-12-29 16:05:21 (GMT)
commit6a39e1cd17c88c62439a2174dbc0c240074d10b1 (patch)
treea89bbac69ed5fd7fb0e3f613c5c334de5caf9911
parente8ef45fb73bb22cb5118f04ce990047245a43872 (diff)
fix problem with play audio on Ubuntu
-rw-r--r--page.py6
-rw-r--r--utils/play_audio.py59
2 files changed, 56 insertions, 9 deletions
diff --git a/page.py b/page.py
index f17d400..a5db3a4 100644
--- a/page.py
+++ b/page.py
@@ -192,11 +192,11 @@ class Page():
def _play_target_sound(self):
if self._activity.mode == 'find by letter':
- play_audio_from_file(self, os.path.join(
+ play_audio_from_file(os.path.join(
self._sounds_path,
self._media_data[self.target][1]))
else:
- play_audio_from_file(self, os.path.join(
+ play_audio_from_file(os.path.join(
self._sounds_path,
self._media_data[self.target][0]))
self.timeout = None
@@ -222,7 +222,7 @@ class Page():
elif spr in self._pictures:
self.current_card = self._pictures.index(spr)
if self._activity.mode in ['letter', 'picture']:
- play_audio_from_file(self, os.path.join(
+ play_audio_from_file(os.path.join(
self._sounds_path,
self._media_data[self.current_card][1]))
elif self._activity.mode in ['find by letter', 'find by word']:
diff --git a/utils/play_audio.py b/utils/play_audio.py
index 2ed445b..f5c1030 100644
--- a/utils/play_audio.py
+++ b/utils/play_audio.py
@@ -22,13 +22,60 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
-
+import os
import subprocess
-def play_audio_from_file(parent, file_path):
+import logging
+_logger = logging.getLogger('iknowmyabcs-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(file_path):
""" Audio media """
- command_line = ['gst-launch', 'filesrc', 'location=' + file_path,
- '! oggdemux', '! vorbisdec', '! audioconvert',
- '! alsasink']
- subprocess.call(command_line)
+
+ if not hasattr(play_audio_from_file, 'gst_launch'):
+ for path in GST_PATHS:
+ if os.path.exists(path):
+ play_audio_from_file.gst_launch = path
+ _logger.debug(path)
+ break
+
+ if not hasattr(play_audio_from_file, 'gst_launch'):
+ _logger.debug('gst-launch not found')
+ return
+
+ command_line = [play_audio_from_file.gst_launch, 'filesrc',
+ 'location=' + file_path, '! oggdemux', '! vorbisdec',
+ '! audioconvert', '! alsasink']
+ check_output(command_line, 'unable to play audio file %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
+