mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
new osx audio based on qtmovie
This commit is contained in:
parent
83e27a12ce
commit
97eb12e343
1 changed files with 26 additions and 32 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue