Skip to content

Commit 83efd49

Browse files
committed
android/pygame mixer: fix Sound.stop() method (wasnt working at all), and avoid multiple play when multiple call play() are done (same behavior as pygame mixer)
1 parent fe7c849 commit 83efd49

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

recipes/android/src/android_mixer.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ def get_busy(self):
139139
return sound.busy(self.id)
140140

141141
def get_sound(self):
142-
rv = sound.busy(self.id)
143-
if rv is not None:
144-
rv = sounds.get(rv, None)
145-
146-
return rv
147-
142+
is_busy = sound.busy(self.id)
143+
if not is_busy:
144+
return
145+
serial = sound.playing_name(self.id)
146+
if not serial:
147+
return
148+
return sounds.get(serial, None)
148149

149150
def queue(self, s):
150151
self.loop = None
@@ -183,6 +184,7 @@ def __init__(self, what):
183184

184185
global sound_serial
185186

187+
self._channel = None
186188
self.serial = str(sound_serial)
187189
sound_serial += 1
188190

@@ -194,7 +196,12 @@ def __init__(self, what):
194196
sounds[self.serial] = self
195197

196198
def play(self, loops=0, maxtime=0, fade_ms=0):
197-
channel = find_channel(True)
199+
# avoid new play if the sound is already playing
200+
# -> same behavior as standard pygame.
201+
if self._channel is not None:
202+
if self._channel.get_sound() is self:
203+
return
204+
self._channel = channel = find_channel(True)
198205
channel.play(self, loops=loops)
199206
return channel
200207

0 commit comments

Comments
 (0)