Reputation: 21870
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);
}
Upvotes: 12
Views: 5475
Reputation: 5939
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);
});
}
}
}
Upvotes: 3
Reputation: 177
I had a similar issue. It was working fine at one point but had stopped working later on.
I checked the code over and over and I Googled my issue to see if I could find any clues.
It turned out that simply turning the device off and then back on again solved the issue!
Upvotes: 1
Reputation: 2057
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.
Upvotes: 1
Reputation: 6804
In my case, the sound was turned up ok... but the ipad was on Mute. Swipe up from bottom (control center) and unmute
Upvotes: 2
Reputation: 367
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.
Upvotes: 9