]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/music_file.py
Add seek action
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / music_file.py
index b926c64c63a20e1adcc689a70c0e15d69a32ca1b..32869b6891aed831a8b2768016aedf3a83a7fe45 100644 (file)
@@ -129,6 +129,13 @@ class MusicFile(Machine):
 
             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)