小智 53
我发现这个systemSoundID列表对于直接访问声音ID非常有用.
http://iphonedevwiki.net/index.php/AudioServices
例如,播放按键音响.
#define systemSoundID 1104
AudioServicesPlaySystemSound (systemSoundID);
Run Code Online (Sandbox Code Playgroud)
您还需要在项目中添加AudioToolbox框架,并添加#include <AudioToolbox.h>
到.m或.h文件中.
Kri*_*dra 39
此代码播放苹果系统声音"Tock.aiff"..我相信你可以使用它播放不同的系统声音
NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesDisposeSystemSoundID(soundID);
Run Code Online (Sandbox Code Playgroud)
看到这个帖子
https://developer.apple.com/documentation/audiotoolbox/system_sound_services
小智 28
您可以将此用于所有默认系统音频.
例如,对于tap声音用户:
AudioServicesPlaySystemSound(1104);
Run Code Online (Sandbox Code Playgroud)
对于正面声音,请使用:
AudioServicesPlaySystemSound(1054);
Run Code Online (Sandbox Code Playgroud)
并且,负面声音使用此:
AudioServicesPlaySystemSound(1053);
Run Code Online (Sandbox Code Playgroud)
您可以在此处查看完整列表.
TUN*_*R88 16
所有系统声音列表:iOSSystemSoundsLibrary
您可以播放所有这些声音:
AudioServicesPlaySystemSound (systemSoundID);
Run Code Online (Sandbox Code Playgroud)
改编自@ yannc2021
http://iphonedevwiki.net/index.php/AudioServices
如果你想在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)
Run Code Online (Sandbox Code Playgroud)
斯威夫特 4 +
注意:仅在真实设备上试用:
import AVKit
AudioServicesPlaySystemSound(1007);
Run Code Online (Sandbox Code Playgroud)
或者您可以尝试使用 URL 作为 -
let url = URL(fileURLWithPath: "/System/Library/Audio/UISounds/payment_success.caf")
var soundID: SystemSoundID = 0
AudioServicesCreateSystemSoundID(url as CFURL, &soundID)
AudioServicesPlaySystemSound(soundID);
Run Code Online (Sandbox Code Playgroud)
https://github.com/klaas/SwiftySystemSounds/blob/master/README.md
归档时间: |
|
查看次数: |
70302 次 |
最近记录: |