Skip to content

Commit 67e0e1b

Browse files
committed
core.Voice: start/stop/toggle support
1 parent b867993 commit 67e0e1b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

extensions/core.pyx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ cdef class Voice(object):
5353
def __cinit__(
5454
self,
5555
Sound sound,
56-
object on_finish,
56+
object on_finish=None,
5757
int loop=False,
5858
Mixer mixer=None,
5959
):
@@ -62,7 +62,6 @@ cdef class Voice(object):
6262
self.sound = sound
6363
self.mixer = mixer
6464
self.loop = loop
65-
self.handle = NULL
6665

6766
if on_finish:
6867
context = CallbackContext(on_finish, self.sound)
@@ -80,7 +79,7 @@ cdef class Voice(object):
8079
)
8180

8281
else:
83-
handle = gau.create_handle_sound(
82+
self.handle = gau.create_handle_sound(
8483
global_mixer,
8584
self.sound.sound,
8685
<ga.FinishCallback>&gau.on_finish_destroy,
@@ -91,12 +90,25 @@ cdef class Voice(object):
9190
def play(self):
9291
ga.handle_play(self.handle)
9392

93+
@property
94+
def playing(self):
95+
return bool(ga.handle_playing(self.handle))
96+
9497
def stop(self):
9598
ga.handle_stop(self.handle)
9699

100+
@property
101+
def stopped(self):
102+
return bool(ga.handle_stopped(self.handle))
103+
97104
def __del__(self):
98105
ga.handle_destroy(self.handle)
99106

107+
def toggle(self):
108+
if self.playing:
109+
self.stop()
110+
else:
111+
self.play()
100112

101113
cdef class Sound(object):
102114
cdef ga.Sound* sound
@@ -108,7 +120,7 @@ cdef class Sound(object):
108120
if not stream:
109121
self.sound = gau.load_sound_file(filename, ext)
110122
else:
111-
raise NotImplementedError("streams ntt implemented yet")
123+
raise NotImplementedError("streams not implemented yet")
112124

113125
def play(self, on_finish=None):
114126
cdef Voice voice

0 commit comments

Comments
 (0)