Add error handling to wxSound under wxOSX.

Don't assume that we can open any file as a sound, check for the return value
from AudioServicesCreateSystemSoundID().

(this is a backport of ba4d3d31a6 from master)
This commit is contained in:
Vadim Zeitlin
2014-04-12 22:56:21 +00:00
parent d62674e81d
commit 7c81707a7e

View File

@@ -112,7 +112,13 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags)
CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
wxCFRef<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
AudioServicesCreateSystemSoundID(url, &m_soundID);
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);