I found several macOS system sounds inside
/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds
including the trash sound when you delete a file in finder in dock/drag to trash.aif
.
However I could not find an API to play any of these sounds. I would really prefer not to hardcode any file paths.
PS: An option would probably be to simply copy the sound to my own app bundle, but I also want to avoid that if possible (also licensing?).
CodePudding user response:
Import AudioToolbox
framework and use AudioServicesPlaySystemSound
function. The argument values are not documented and are subject to change the same as the hard coded paths. It should pass the app store review as it's not private API.
//drag to trash.aif
AudioServicesPlaySystemSound(0x10);
//poof item of dock.aif
AudioServicesPlaySystemSound(0xf);
The only documented values are:
CF_ENUM(SystemSoundID)
{
kSystemSoundID_UserPreferredAlert = 0x00001000,
kSystemSoundID_FlashScreen = 0x00000FFE,
// this has been renamed to be consistent
kUserPreferredAlert = kSystemSoundID_UserPreferredAlert
};
Here is list of undocumented values
1 "Volume Mount.aif"
2 "Volume Unmount.aif"
3 "Media Keys.aif"
4 "Sticky Keys ON.aif"
5 "Sticky Keys OFF.aif"
6 "Sticky Keys MODIFER.aif"
7 "Sticky Keys Locked.aif"
8 "Sticky Keys Stuck.aif"
9 "Mouse Keys ON.aif"
10 "Mouse Keys OFF.aif"
11 "Slow Keys, 1st Key Pressed.aif"
12 "Slow Keys, Key Registered.aif"
13 "empty trash.aif"
14 "move to trash.aif"
15 "poof item off dock.aif"
16 "drag to trash.aif"
17 "InkSoundBecomeMouse.aif"
18 "InkSoundStroke1.aif"
19 "InkSoundStroke2.aif"
20 "InkSoundStroke3.aif"
21 "InkSoundStroke4.aif"
22 "burn complete.aif"
23 "burn failed.aif"
24 "Grab.aif"