diff options
author | Walter Bender <walter.bender@gmail.com> | 2012-12-29 16:11:38 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2012-12-29 16:11:38 (GMT) |
commit | f59b2031db0dde0291377243604551278024dd16 (patch) | |
tree | 90848f834b80aa2c7ba4132dd2daf068b46427d8 | |
parent | 691d305b04ec884d302be78656d4d1695510f220 (diff) |
generalize play_audio for more systemsv3
-rw-r--r-- | page.py | 6 | ||||
-rw-r--r-- | utils/play_audio.py | 35 |
2 files changed, 32 insertions, 9 deletions
@@ -186,11 +186,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 @@ -216,7 +216,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..9a6eedf 100644 --- a/utils/play_audio.py +++ b/utils/play_audio.py @@ -22,13 +22,36 @@ # 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'] + subprocess.check_output(command_line) |