I've had this code in my apps since iOS3 and it has been working. As far I know, these libraries didn't get changed at all in iOS8, but it's not working in iOS8. It doesn't crash or anything, it just never plays the sound effect.
Any ideas?
static void completionCallback (SystemSoundID mySSID, void* myself) {
AudioServicesRemoveSystemSoundCompletion(mySSID);
AudioServicesDisposeSystemSoundID(mySSID);
}
+ (void) playSound: (NSString *)path {
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, NULL);
AudioServicesPlaySystemSound(soundID);
}
I have found the answer to mine problem, it may fix yours. I went into the settings and changed the volume of the Ringer and Alerts, this was on the Sounds section. Mine was set to nil for some reason. I did not realise that AudioServices were connect to this sound level. For my needs I'm probably going to switch to using AVAudioPlayer.
I know this is a bit old post. But I encountered this issue recently and this is my solution to the issue.
Go to settings
>sounds
>Ringer and alerts
. Increase the volume and try to play the sound.Most probably this will work.
Also the code that you are using will get deprecated soon.Use the following.
+(void)playClickSound
{
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"click_sound.mp3" withExtension:nil]; //filename can include extension e.g. @"bang.wav"
if (fileURL)
{
SystemSoundID theSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)fileURL, &theSoundID);
if (error == kAudioServicesNoError)
{
AudioServicesPlaySystemSoundWithCompletion(theSoundID, ^{
AudioServicesDisposeSystemSoundID(theSoundID);
});
}
}
}
In my case, the sound was turned up ok... but the ipad was on Mute. Swipe up from bottom (control center) and unmute
For me it was the ring/silent switch that was flipped (the switch above the up/down volume buttons). SpriteKit sounds still worked perfectly fine, so this behavior is quite annoying.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With