AudioServicesPlaySystemSound does not play sound on iOS 8 device

I have AVFoundationand AudioToolboxframes added to my project. In the class from where I want to reproduce the system sound, I #include <AudioToolbox/AudioToolbox.h>, and I call AudioServicesPlaySystemSound(1007);. I am testing the device with iOS 8sounds turned on and the volume is high enough, but I don’t hear any system sound when the application starts and it’s AudioServicesPlaySystemSound(1007);called ... what can I skip?

+4
source share
5 answers

This will result in a system sound.

But remember that system sound does not produce longer sound.

NSString *pewPewPath  = [[NSBundle mainBundle] pathForResource:@"engine" ofType:@"mp3"];
NSURL *pewPewURL = [NSURL fileURLWithPath:pewPewPath];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)pewPewURL, &_engineSound);
AudioServicesPlaySystemSound(_engineSound);
+2
source

iOS10 , , :

SystemSoundID audioID;

AudioServicesCreateSystemSoundID((__bridge CFURLRef)pathURL, &mySSID);
AudioServicesPlaySystemSound(audioID);

:

AudioServicesCreateSystemSoundID((__bridge CFURLRef)pathURL, &audioID);

AudioServicesPlaySystemSoundWithCompletion(audioID, ^{
    AudioServicesDisposeSystemSoundID(audioID);
});
+6

:

(AudioServicesPlaySystemSound()) . AudioServicesPlaySystemSoundWithCompletion .

:

NSURL *fileURL = [[NSBundle mainBundle] URLForResource:filename 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);
        });
    }
}

, , .

, , , ( / MAC-, , " " )/p >

+3

iPad iPhone iOS 8, .

For some very strange reason, it doesn’t work on the iOS 8 simulator for any device, even if it works on iOS 7 and 7.1 simulators.

Otherwise, the code below works fine on all real devices.

NSString *pewPewPath  = [[NSBundle mainBundle] pathForResource:@"engine" ofType:@"mp3"];
NSURL *pewPewURL = [NSURL fileURLWithPath:pewPewPath];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)pewPewURL, &_engineSound);
AudioServicesPlaySystemSound(_engineSound);
0
source

for fast 3.x and xcode 8:

var theSoundID : SystemSoundID = 0
let bundleURL = Bundle.main.bundleURL
let url = bundleURL.appendingPathComponent("Invitation.aiff")

let urlRef = url as CFURL

let err = AudioServicesCreateSystemSoundID(urlRef, &theSoundID)
if err == kAudioServicesNoError{
    AudioServicesPlaySystemSoundWithCompletion(theSoundID, {
        AudioServicesDisposeSystemSoundID(theSoundID)
    })
}
0
source

Source: https://habr.com/ru/post/1606693/


All Articles