Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/audio.py
diff options
context:
space:
mode:
Diffstat (limited to 'audio.py')
-rw-r--r--audio.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/audio.py b/audio.py
new file mode 100644
index 0000000..d9b69c7
--- /dev/null
+++ b/audio.py
@@ -0,0 +1,62 @@
+# Copyright (C) 2006, 2007, 2008 One Laptop Per Child
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import gst
+import logging
+
+_logger = logging.getLogger('memorize-activity')
+
+class Audio:
+ def __init__(self):
+ self._player = gst.element_factory_make('playbin', 'player')
+ fakesink = gst.element_factory_make('fakesink', 'my-fakesink')
+ self._player.set_property('video-sink', fakesink)
+ self._playing = None
+
+ bus = self._player.get_bus()
+ bus.add_signal_watch()
+ bus.connect('message', self._gstmessage_cb)
+
+ def play(self, filename=None):
+ if filename:
+ _logger.debug('play audio %s' % filename)
+ self._player.set_property('uri', 'file://' + filename)
+ self._player.set_state(gst.STATE_NULL)
+ elif self._playing == None:
+ return
+ else:
+ _logger.debug('continue audio')
+
+ self._player.set_state(gst.STATE_PLAYING)
+ self._playing = True
+
+ def pause(self):
+ if self._playing != None:
+ _logger.debug('pause audio')
+ self._player.set_state(gst.STATE_PAUSED)
+ self._playing = False
+
+ def stop(self):
+ self._player.set_state(gst.STATE_NULL)
+
+ def _gstmessage_cb(self, bus, message):
+ type = message.type
+
+ if type in (gst.MESSAGE_EOS, gst.MESSAGE_ERROR):
+ self._player.set_state(gst.STATE_NULL)
+ self._playing = None
+ _logger.debug('audio stoped with type %d' % type)