new osx audio based on qtmovie

This commit is contained in:
Damien Elmes 2009-02-26 02:07:27 +09:00
parent 83e27a12ce
commit 97eb12e343

View file

@ -226,49 +226,43 @@ class PyAudioRecorder(_Recorder):
########################################################################## ##########################################################################
try: try:
from AppKit import NSSound, NSObject from QTKit import QTMovie
from AppKit import NSAutoreleasePool
queue = [] class QTMovieQueueMonitor(threading.Thread):
current = None
class Sound(NSObject): def run(self):
pool = NSAutoreleasePool.alloc().init()
def init(self): current = None
return self
def sound_didFinishPlaying_(self, sound, bool):
global current
while 1: while 1:
if not queue: time.sleep(0.1)
break if current:
next = queue.pop(0) if (current.currentTime().timeValue >=
if play_(next): current.duration().timeValue):
break current = None
continue
s = Sound.new() if queue:
current = queue.pop(0)
current.play()
continue
del pool
return
def playOSX(path): def playOSX(path):
global current global manager
path = path.encode(sys.getfilesystemencoding())
current = QTMovie.alloc()
(current, err) = current.initWithFile_error_(path)
if current: if current:
if current.isPlaying(): queue.append(current)
queue.append(path) if not manager or not manager.isAlive():
return manager = QTMovieQueueMonitor()
# new handle manager.start()
play_(path)
def clearQueueOSX(): def clearQueueOSX():
global queue global queue
queue = [] queue = []
def play_(path):
global current
current = NSSound.alloc()
current = current.initWithContentsOfFile_byReference_(path, True)
if not current:
return False
current.setDelegate_(s)
current.play()
return True
except ImportError: except ImportError:
pass pass