Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing system sound without importing your own

Is it possible to play already existing system sounds without importing your own?

like image 663
Oksana Avatar asked Oct 20 '11 05:10

Oksana


5 Answers

I find this list of systemSoundID very useful for accessing the sound ID directly.
http://iphonedevwiki.net/index.php/AudioServices

For example, to play a key press tock sound.

#define systemSoundID    1104
AudioServicesPlaySystemSound (systemSoundID);

You'll also need to add the AudioToolbox framework in your project, and add #include <AudioToolbox.h> to your .m or .h file.

like image 167
yannc2021 Avatar answered Nov 20 '22 17:11

yannc2021


This code plays apple system sound "Tock.aiff"..I believe you can play different system sounds using this

NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesDisposeSystemSoundID(soundID);

See this thread

Apple's documentation on System sounds

https://developer.apple.com/documentation/audiotoolbox/system_sound_services

like image 34
Krishnabhadra Avatar answered Nov 20 '22 18:11

Krishnabhadra


You can use this for all default system audio.

Example, for the tap sound user this:

AudioServicesPlaySystemSound(1104);

For positive sounds, use this:

 AudioServicesPlaySystemSound(1054);

And, negative sounds use this:

 AudioServicesPlaySystemSound(1053);

The complete list you can see here.

like image 32
Matheus Veloza Avatar answered Nov 20 '22 17:11

Matheus Veloza


List of all system sounds: iOSSystemSoundsLibrary

After you import AVKit, you can play all this sounds with:

AudioServicesPlaySystemSound (systemSoundID);
like image 18
TUNER88 Avatar answered Nov 20 '22 17:11

TUNER88


adapted from @yannc2021

http://iphonedevwiki.net/index.php/AudioServices

if you want to use system sound in Swift

// import this
import AVFoundation

// add this method
required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

// declared system sound here
let systemSoundID: SystemSoundID = 1104

// to play sound
AudioServicesPlaySystemSound (systemSoundID)
like image 6
Sruit A.Suk Avatar answered Nov 20 '22 16:11

Sruit A.Suk