aboutsummaryrefslogtreecommitdiff
path: root/helpers/music_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/music_file.py')
-rw-r--r--helpers/music_file.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/helpers/music_file.py b/helpers/music_file.py
index 5101f7f..f6b0117 100644
--- a/helpers/music_file.py
+++ b/helpers/music_file.py
@@ -3,9 +3,9 @@ import pydub
3import pygame 3import pygame
4 4
5class MusicFile: 5class MusicFile:
6 def __init__(self, filename, lock): 6 def __init__(self, filename, lock, channel_id):
7 self.filename = filename 7 self.filename = filename
8 self.channel = None 8 self.channel_id = channel_id
9 self.raw_data = None 9 self.raw_data = None
10 self.sound = None 10 self.sound = None
11 11
@@ -22,7 +22,7 @@ class MusicFile:
22 lock.release() 22 lock.release()
23 23
24 def is_playing(self): 24 def is_playing(self):
25 return self.channel is not None and self.channel.get_busy() 25 return self.channel().get_busy()
26 26
27 def play(self, fade_in = 0, volume = 100, start_at = 0): 27 def play(self, fade_in = 0, volume = 100, start_at = 0):
28 self.set_volume(volume) 28 self.set_volume(volume)
@@ -36,18 +36,16 @@ class MusicFile:
36 else: 36 else:
37 self.sound = pygame.mixer.Sound(self.raw_data) 37 self.sound = pygame.mixer.Sound(self.raw_data)
38 38
39 self.channel = self.sound.play(fade_ms = fade_in * 1000) 39 self.channel().play(self.sound, fade_ms = fade_in * 1000)
40 40
41 def pause(self): 41 def pause(self):
42 if self.channel is not None: 42 self.channel().pause()
43 self.channel.pause()
44 43
45 def stop(self, fade_out = 0): 44 def stop(self, fade_out = 0):
46 self.channel = None
47 if fade_out > 0: 45 if fade_out > 0:
48 self.sound.fadeout(fade_out * 1000) 46 self.channel().fadeout(fade_out * 1000)
49 else: 47 else:
50 self.sound.stop() 48 self.channel().stop()
51 49
52 def set_volume(self, value): 50 def set_volume(self, value):
53 if value < 0: 51 if value < 0:
@@ -58,3 +56,6 @@ class MusicFile:
58 56
59 def wait_end(self): 57 def wait_end(self):
60 pass 58 pass
59
60 def channel(self):
61 return pygame.mixer.Channel(self.channel_id)