Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioServicesPlaySystemSound not working in iOS8

Tags:

ios8

audio

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);
}
like image 418
Kenny Wyland Avatar asked Sep 22 '14 16:09

Kenny Wyland


4 Answers

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.

like image 67
Paul Andrew Herbert Avatar answered Nov 17 '22 14:11

Paul Andrew Herbert


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);
            });
        }
    }
}
like image 40
abhimuralidharan Avatar answered Nov 17 '22 12:11

abhimuralidharan


In my case, the sound was turned up ok... but the ipad was on Mute. Swipe up from bottom (control center) and unmute

like image 2
xaphod Avatar answered Nov 17 '22 14:11

xaphod


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.

like image 1
Cesar Avatar answered Nov 17 '22 13:11

Cesar