Test commit
[couchpytato.git] / sdlmixer.py
blobcd7019b9ca42a1838115ba2c7228aa2f1d90a6b9
1 import pygame.mixer, time
3 class Music:
4 def __init__(self):
5 self.playing = False
6 self.paused = False
7 pygame.mixer.init()
9 def isplaying(self):
10 return pygame.mixer.music.get_busy()
12 def play(self, name=None):
13 ok = True
14 if self.paused:
15 pygame.mixer.music.unpause()
16 self.playing = True
17 self.paused = False
18 elif name:
19 try:
20 pygame.mixer.music.load(name)
21 except:
22 ok = False
23 if ok:
24 pygame.mixer.music.play()
25 self.playing = True
26 self.paused = False
27 else:
28 ok = False
29 return ok
31 def pause(self):
32 if self.isplaying():
33 pygame.mixer.music.pause()
34 self.playing = False
35 self.paused = True
37 def time(self, what=0):
38 if self.isplaying():
39 secs = int(pygame.mixer.music.get_pos()/1000)
40 tim = time.localtime(secs)
41 min = str(tim[4])
42 sec = str(tim[5])
43 if len(min) == 1:
44 min = '0' + min
45 if len(sec) == 1:
46 sec = '0' + sec
47 return min + ':' + sec
48 else:
49 return None
51 def stop(self):
52 if self.isplaying():
53 pygame.mixer.music.stop()
54 self.playing = 0