diff --git a/docs/changes.txt b/docs/changes.txt index 1a7c6ca584..fc0acbdba4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -637,6 +637,7 @@ wxOSX: - Fix using wxHTTP and wxFTP from worker thread. - Fix wxFileDialog::GetFilterIndex() for file open dialogs (phsilva). - Fix custom paper support (tijsv). +- Return false from wxSound::Create()/IsOk() if the file doesn't exist. 3.0.2: (released 2014-10-06) diff --git a/src/osx/core/sound.cpp b/src/osx/core/sound.cpp index 120a807545..327de35cde 100644 --- a/src/osx/core/sound.cpp +++ b/src/osx/core/sound.cpp @@ -34,9 +34,9 @@ class wxOSXAudioToolboxSoundData : public wxSoundData { public: - wxOSXAudioToolboxSoundData(const wxString& fileName); + explicit wxOSXAudioToolboxSoundData(SystemSoundID soundID); - ~wxOSXAudioToolboxSoundData(); + virtual ~wxOSXAudioToolboxSoundData(); virtual bool Play(unsigned flags); @@ -46,14 +46,12 @@ protected: void SoundCompleted(); SystemSoundID m_soundID; - wxString m_sndname; //file path bool m_playing; }; -wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(const wxString& fileName) : - m_soundID(0) +wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(SystemSoundID soundID) : + m_soundID(soundID) { - m_sndname = fileName; m_playing = false; } @@ -108,17 +106,6 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags) m_flags = flags; - wxCFRef cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(m_sndname))); - CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); - wxCFRef url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); - - OSStatus err = AudioServicesCreateSystemSoundID(url, &m_soundID); - if ( err != 0 ) - { - wxLogError(_("Failed to load sound from \"%s\" (error %d)."), m_sndname, err); - return false; - } - AudioServicesAddSystemSoundCompletion( m_soundID, CFRunLoopGetCurrent(), NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this ); bool sync = !(flags & wxSOUND_ASYNC); @@ -149,7 +136,20 @@ bool wxSound::Create(const wxString& fileName, bool isResource) { wxCHECK_MSG( !isResource, false, "not implemented" ); - m_data = new wxOSXAudioToolboxSoundData(fileName); + wxCFRef cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(fileName))); + CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); + wxCFRef url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); + + SystemSoundID soundID; + OSStatus err = AudioServicesCreateSystemSoundID(url, &soundID); + if ( err != 0 ) + { + wxLogError(_("Failed to load sound from \"%s\" (error %d)."), fileName, err); + return false; + } + + m_data = new wxOSXAudioToolboxSoundData(soundID); + return true; }