File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 2020 gobject = None
2121
2222
23+ # Cocoa via PyObjC
24+ try :
25+ import AppKit
26+ except :
27+ AppKit = None
28+
29+
2330# WinMCI
2431if sys .platform == 'win32' :
2532 try :
@@ -148,6 +155,30 @@ def close(self):
148155 pass
149156
150157
158+ class AppKitBackend (Backend ):
159+ def __init__ (self , parent , temp_dir ):
160+ self ._sound = None
161+
162+ def stop (self ):
163+ if self ._sound :
164+ self ._sound .stop ()
165+
166+ def play (self , data ):
167+ if self ._sound :
168+ self ._sound .stop ()
169+
170+ with NamedTemporaryFile (mode = 'w+b' , prefix = '' ,
171+ suffix = '.tmp.mp3' , delete = False ) as f :
172+ f .write (data )
173+
174+ self ._sound = AppKit .NSSound .alloc ()
175+ self ._sound .initWithContentsOfFile_byReference_ (f .name , True )
176+ self ._sound .play ()
177+
178+ def close (self ):
179+ self .stop ()
180+
181+
151182class PhononBackend (Backend ):
152183 def __init__ (self , parent , temp_dir ):
153184 self ._player = Phonon .createPlayer (Phonon .NoCategory )
@@ -190,6 +221,8 @@ def close(self):
190221
191222def create_soundplayer (parent , temp_dir ):
192223 backends = []
224+ if AppKit :
225+ backends .append (AppKitBackend )
193226 if mp3play :
194227 backends .append (WinMCIBackend )
195228 if gst :
You can’t perform that action at this time.
0 commit comments