1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/sound.cpp
3 // Purpose: wxSound class implementation: optional
5 // Modified by: Stefan Csomor
7 // RCS-ID: $Id: sound.cpp 61475 2009-07-20 16:47:54Z VZ $
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #if wxOSX_USE_AUDIOTOOLBOX
22 #include "wx/object.h"
23 #include "wx/string.h"
31 class wxOSXAudioToolboxSoundData
: public wxSoundData
34 wxOSXAudioToolboxSoundData(const wxString
& fileName
);
36 ~wxOSXAudioToolboxSoundData();
38 virtual bool Play(unsigned flags
);
40 virtual void DoStop();
42 static void CompletionCallback(SystemSoundID mySSID
, void * soundRef
);
43 void SoundCompleted();
45 SystemSoundID m_soundID
;
46 wxString m_sndname
; //file path
49 wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(const wxString
& fileName
) :
55 void wxOSXAudioToolboxSoundData::CompletionCallback(SystemSoundID mySSID
, void * soundRef
)
57 wxOSXAudioToolboxSoundData
* data
= (wxOSXAudioToolboxSoundData
*) soundRef
;
59 data
->SoundCompleted();
62 void wxOSXAudioToolboxSoundData::SoundCompleted()
64 if ( m_flags
& wxSOUND_ASYNC
)
66 if (m_flags
& wxSOUND_LOOP
)
67 AudioServicesPlaySystemSound(m_soundID
);
74 CFRunLoopStop(CFRunLoopGetCurrent());
79 void wxOSXAudioToolboxSoundData::DoStop()
83 AudioServicesDisposeSystemSoundID (m_soundID
);
86 wxSound::SoundStopped(this);
90 bool wxOSXAudioToolboxSoundData::DoPlay(unsigned flags
) const
96 wxCFRef
<CFMutableStringRef
> cfMutableString(CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(m_sndname
)));
97 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
98 wxCFRef
<CFURLRef
> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kCFURLPOSIXPathStyle
, false));
100 AudioServicesCreateSystemSoundID(url
, &m_soundID
);
101 AudioServicesAddSystemSoundCompletion( m_soundID
, NULL
, NULL
, wxOSXAudioToolboxSoundData::CompletionCallback
, (void *) this );
103 bool sync
= !(flags
& wxSOUND_ASYNC
);
105 AudioServicesPlaySystemSound(m_soundID
);
118 #endif // wxOSX_USE_AUDIOTOOLBOX