1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
import gtk
import gst
from gettext import gettext as _
import Theme
from Utils import *
from sugar.activity.activity import get_bundle_path
speaker = Theme.pixmap('images/sounds/speaker.png')
THEMES = (
{ 'name' : _('Gobble'),
'pixbuf': speaker,
'sound' : 'sounds/gobble.wav' },
{ 'name' : _('Funk'),
'pixbuf': speaker,
'sound' : 'sounds/funk.wav' },
{ 'name' : _('Giggle'),
'pixbuf': speaker,
'sound' : 'sounds/giggle.wav' },
{ 'name' : _('Jungle'),
'pixbuf': speaker,
'sound' : 'sounds/jungle.wav' },
{ 'name' : _('Mute'),
'pixbuf': Theme.pixmap('images/sounds/mute.png'),
'sound' : None },
None,
{ 'name' : _('Custom'),
'pixbuf': Theme.pixmap('images/sounds/custom.png'),
'sound' : None } )
theme = FileInstanceVariable(THEMES[0])
playing = FileInstanceVariable(False)
def play():
playing.set(True)
change(theme.get())
def stop():
playing.set(False)
player.set_state(gst.STATE_NULL)
def change(a_theme):
if not a_theme: return
theme.set(a_theme)
import logging
logging.error(theme['name'])
if not playing.get(): return
player.set_state(gst.STATE_NULL)
sound = theme['sound']
if not sound: return
player.set_property('uri', 'file://' + Theme.path(sound))
player.set_state(gst.STATE_NULL)
player.set_state(gst.STATE_PLAYING)
# GSTREAMER STUFF
def _gstmessage_cb(bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
# END OF SOUND FILE
player.set_state(gst.STATE_NULL)
player.set_state(gst.STATE_PLAYING)
elif t == gst.MESSAGE_ERROR:
player.set_state(gst.STATE_NULL)
player = gst.element_factory_make("playbin", "player")
fakesink = gst.element_factory_make('fakesink', "my-fakesink")
player.set_property("video-sink", fakesink)
bus = player.get_bus()
bus.add_signal_watch()
bus.connect('message', _gstmessage_cb)
|