I'm trying to get a sound to play but when I code:
AudioServicesCreateSystemSoundID ((CFURLRef) alertSound, &soundFileObject);
it throws the following error:
Cast of Objective-C pointer type 'NSURL *' to C pointer type 'CFURLRef' (aka 'const struct __CFURL *') requires a bridged cast error
I have tried both of the two following suggested solutions:
AudioServicesCreateSystemSoundID ((__bridge CFURLRef) alertSound, &soundFileObject);
or
AudioServicesCreateSystemSoundID ((CFURLRef) CFBridgingRetain(alertSound), &soundFileObject);
But I still can't get the sound to play.
I guess the question is: is the bridging error the cause of the sound not playing, or should I be looking else where?
I can get the sound to play using the SysSound sample code and I'm using iOS 6 and Xcode 4.5.
Thanks for any pointers :)
The cast is probably not the reason the sound is not playing:
is fine.
Most likely your error is in code that you have not shown us. A common problem is an error in the URL creation or an invalid file format.
Modify your code as follows:
and check what status code you get;
parmErr
(-50) is relatively common and usually means your URL is nil.Oh, and one more thought, you don't show where you're actually playing the sound. You do know that
AudioServicesCreateSystemSoundID
does not actually play the sound. You need to call:Apologies if you knew that already!