else:
return 0
- def play(self, fade_in = 0, volume = 100, start_at = 0):
+ def play(self, fade_in = 0, volume = 100, loop = 0, start_at = 0):
db_gain = gain(volume) + self.mapping.master_gain
self.volume = volume
+ self.loop = loop
ms = int(start_at * 1000)
ms_fi = max(1, int(fade_in * 1000))
with self.music_lock:
self.current_audio_segment = (self.audio_segment + db_gain).fade(from_gain=-120, duration=ms_fi, start=ms)
- self.before_loaded_playing(initial_frame = int(start_at * self.audio_segment.frame_rate))
+ self.initial_frame = int(start_at * self.audio_segment.frame_rate)
+ self.before_loaded_playing()
self.start_playing()
- def before_loaded_playing(self, initial_frame = 0):
- self.current_frame = initial_frame
+ def before_loaded_playing(self):
+ self.current_frame = self.initial_frame
with self.music_lock:
segment = self.current_audio_segment
)
self.current_frame += frame_count
if len(audio_segment) == 0:
- raise sd.CallbackStop
+ if self.is_loaded_playing() and self.loop != 0:
+ self.loop -= 1
+ self.current_frame = self.initial_frame
+ else:
+ raise sd.CallbackStop
out_data[:] = audio_segment.ljust(len(out_data), b'\0')
+ def seek(self, value = 0, delta = False):
+ # We don't want to do that while stopping
+ if not (self.is_loaded_playing() or self.is_loaded_paused()):
+ return
+ with self.music_lock:
+ self.current_frame = max(0, int(delta) * self.current_frame + int(value * self.audio_segment.frame_rate))
+
def stop(self, fade_out = 0, wait = False):
if self.is_loaded_playing():
ms = int(self.sound_position * 1000)