From 3bd9dd84944d0053d19daede3cf26d97b04e14ae Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 6 Mar 2009 06:35:43 +0900 Subject: [PATCH] handle osx 10.3 audio --- anki/sound.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/anki/sound.py b/anki/sound.py index 873519f9f..9b4386b8c 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -270,7 +270,56 @@ try: queue = [] except ImportError: - pass + # fall back to old nssound code for 10.3 + + try: + + from AppKit import NSSound, NSObject + + queue = [] + current = None + + class Sound(NSObject): + + def init(self): + return self + + def sound_didFinishPlaying_(self, sound, bool): + global current + while 1: + if not queue: + break + next = queue.pop(0) + if play_(next): + break + + s = Sound.new() + + def playOSX(path): + global current + if current: + if current.isPlaying(): + queue.append(path) + return + # new handle + playOSX_(path) + + def clearQueueOSX(): + global queue + queue = [] + + def playOSX_(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: + pass # Default audio player ##########################################################################