Exemple #1
0
class Track(object):
    volume = 1.0
    volume_add = None
    sound = None
    def __init__(self, filename):
        self.filename = filename
    
    def set_volume(self, volume):
        self.volume = volume / 100.0
        if self.sound is not None:
            self.sound.volume = self.volume
    
    def play(self):
        if self.sound is not None:
            return
        self.sound = Sound(filename = self.filename)
        self.sound.volume = self.volume
        self.sound.play(0)

    def stop(self):
        if self.sound is None:
            return
        self.sound.close()
        self.sound = None
    
    def update(self, dt):
        if self.volume_add is None:
            return
        self.volume += self.volume_add
        self.sound.volume = self.volume
        if self.volume < 0.0 or self.volume > 1.0:
            self.volume = max(0.0, min(1.0, self.volume))
            self.volume_add = None
            self.stop()

    def is_playing(self):
        return self.sound is not None
Exemple #2
0
 def play(self):
     if self.sound is not None:
         return
     self.sound = Sound(filename = self.filename)
     self.sound.volume = self.volume
     self.sound.play(0)