我正在使用 pygame + Twisted。我做了一个Sound
包装类,其相关部分在这里:
class Sound(object):
def __init__(self, sound):
self.sound = sound
self._status_task = task.LoopingCall(self._check_status)
self._status_task.start(0.05)
def _check_status(self):
chans = self.sound.get_num_channels()
if chans > 0:
logger.debug("'%s' playing on %d channels",
self.filename, chans)
def play(self):
self.sound.play()
然而,发生的事情是,在声音播放完之后,.get_num_channels()
返回一个正数,例如:
2013-07-08 15:13:30,502-DEBUG-engine.sound - 'sounds/foo.wav' playing on 2 channels
2013-07-08 15:13:30,503-DEBUG-engine.sound - 'sounds/bar.wav' playing on 1 channels
2013-07-08 15:13:30,546-DEBUG-engine.sound - 'sounds/foo.wav' playing on 2 channels
2013-07-08 15:13:30,558-DEBUG-engine.sound - 'sounds/bar.wav' playing on 1 channels
2013-07-08 15:13:30,602-DEBUG-engine.sound - 'sounds/foo.wav' playing on 2 channels
为什么会这样?
我问是因为有时当我告诉它时声音根本不播放,我正试图深入了解它。我认为理解这可能有助于解决该错误。