1
1
from threading import Thread
6
8
class RepeatSound(Thread):
7
def __init__(self, howmanytimes, button, volume, PlayerInstance):
9
def __init__(self, howmanytimes, button, volume, PlayerInstance, MainClass, sndfile):
9
11
Thread.__init__(self)
11
13
self.setDaemon(True)
14
self.sndfile = sndfile
13
15
self.button = button
14
self.times = howmanytimes - 1
16
self.times = howmanytimes
15
17
self.bus = PlayerInstance.get_bus()
16
18
self.bus.add_signal_watch()
17
19
self.bus.connect('message', self.BusMessage)
21
23
self.volume = volume / 100
22
24
self.PlayerInstance = PlayerInstance
26
25
self.PlayerInstance.set_property("volume", self.volume)
27
self.MainClass = MainClass
27
28
self.PlayerInstance.set_state(gst.STATE_PLAYING)
30
while self.Repeated < self.times and \
31
self.PlayerInstance.get_state()[1] != gst.STATE_NULL:
37
while self.PlayerInstance.get_state()[1] != gst.STATE_NULL: continue
29
self.PlayAgain = False
31
while self.stillrun or self.Repeated <= self.times or self.times == -1:
34
if not self.Repeated < self.times - 1 and not self.times == -1: break
35
self.PlayerInstance.set_property('uri', "file://" + self.sndfile)
36
self.PlayerInstance.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, 0)
37
self.PlayerInstance.set_state(gst.STATE_PLAYING)
43
self.PlayAgain = False
47
if self.PlayerInstance.get_state()[1] == gst.STATE_NULL:
39
53
self.PlayerInstance.set_property("volume", 0)
40
54
self.PlayerInstance.set_state(gst.STATE_NULL)
43
57
gtk.gdk.threads_enter()
44
self.button.set_sensitive(False)
58
self.MainClass.StopTheSound()
59
self.PlayerInstance.set_state(gst.STATE_NULL)
45
60
gtk.gdk.threads_leave()
47
64
def BusMessage(self, Bus, Message):
65
if not self.MainClass.WhatPlaying == "R": return
66
if self.PlayerInstance.get_state()[1] == gst.STATE_NULL: return
48
67
if Message.type == gst.MESSAGE_EOS:
49
self.PlayerInstance.set_state(gst.STATE_PAUSED)
50
self.PlayerInstance.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, 0)
51
self.PlayerInstance.set_property("volume", self.volume)
52
self.PlayerInstance.set_state(gst.STATE_PLAYING)
69
if self.Repeated == self.times and not self.times < 0:
70
gtk.gdk.threads_enter()
71
self.MainClass.StopTheSound()
72
gtk.gdk.threads_leave()