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>2013-01-07 02:32:13 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-01-07 02:32:13 (GMT)
commitf7750fe0a9c7cf7d084e753dca8ce01bbe2823aa (patch)
treed1fca2d1e93470430098425bf286320e8485e222
parent063c2da3933a40a974e3059ac9d4e76c26621b51 (diff)
add pause to play_audio
-rw-r--r--page.py8
-rw-r--r--utils/play_audio.py78
2 files changed, 30 insertions, 56 deletions
diff --git a/page.py b/page.py
index 040f967..ebaf1ee 100644
--- a/page.py
+++ b/page.py
@@ -208,7 +208,7 @@ class Page():
if self.timeout is not None:
gobject.source_remove(self.timeout)
- self.timeout = gobject.timeout_add(1000, self._play_target_sound)
+ self.timeout = gobject.timeout_add(1000, self._play_target_sound, False)
def _bad_answer(self, i):
''' Make sure answer is unique '''
@@ -221,11 +221,11 @@ class Page():
return True
return False
- def _play_target_sound(self):
+ def _play_target_sound(self, queue=True):
if self._activity.mode == 'letter':
- play_audio_from_file(self._card_data[self.target][-1])
+ play_audio_from_file(self._card_data[self.target][-1], queue)
else:
- play_audio_from_file(self.chosen_image[-1])
+ play_audio_from_file(self.chosen_image[-1], queue)
self.timeout = None
def _button_press_cb(self, win, event):
diff --git a/utils/play_audio.py b/utils/play_audio.py
index c06a663..26ee031 100644
--- a/utils/play_audio.py
+++ b/utils/play_audio.py
@@ -1,10 +1,10 @@
"""
aplay.py
- refactored based on Jukebox Activity
Copyright (C) 2007 Andy Wingo <wingo@pobox.com>
Copyright (C) 2007 Red Hat, Inc.
Copyright (C) 2008-2010 Kushal Das <kushal@fedoraproject.org>
Copyright (C) 2010-11 Walter Bender
+ Copyright (C) 2013-14 Aneesh Dogra <lionaneesh@gmail.com>
"""
# This program is free software; you can redistribute it and/or
@@ -22,60 +22,34 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
-import os
-import subprocess
-
+import gst
import logging
+import time
+import gobject
_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(file_path):
+def play_audio_from_file(file_path, queue=False):
""" Audio media """
+ if hasattr(play_audio_from_file, 'player') and \
+ play_audio_from_file.player:
+ if queue:
+ time.sleep(0.2)
+ f = gst.Format(gst.FORMAT_TIME)
+ duration = play_audio_from_file.player.query_duration(f)[0]
+ timeout = duration / 1000000000.
+ gobject.timeout_add(int(timeout * 1000), play_audio_from_file, file_path)
+ return
+ else:
+ play_audio_from_file.player.set_state(gst.STATE_NULL)
+
+
+ play_audio_from_file.player = gst.parse_launch ( \
+ "filesrc location=%s" \
+ " ! oggdemux ! vorbisdec !" \
+ "audioconvert ! alsasink" % (file_path,))
+
+ if not play_audio_from_file.player:
+ _logger.warning('unable to play audio file %s' % (file_path))
- 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
-
-
+ play_audio_from_file.player.set_state(gst.STATE_PLAYING)