OSX/iOS 播放系统声音
方法1:
系统会自带了些声音,有时候一些操作用必要自己播放一下声音提醒一下,用bash的直接say something就ok了,写代码的时候呢?原来很简单的,一句:
[[NSSound soundNamed:@"Hero"] play];
就ok了, 其中Hero是文件名,具体都有啥文件名去这里找
/System/Library/Sounds
一般的文件名列表:
Basso
Blow
Bottle
Frog
Funk
Glass
Hero
Morse
Ping
Pop
Purr
Sosumi
Submarine
Tink
哎,so easy
译自:Playing system sounds, 转自Rainbird的个人博客
方法二:
There are some predefined system sounds, for the system sound ID in the range 1000 to 2000 (decimal), as shown below (from 2.0 to 5.0 beta). The system sounds are all stored in
/System/Library/Audio/UISounds/
| Sound ID | File name (iPhone) | File name (iPod Touch) | Category | Note |
|---|---|---|---|---|
| 1000 | new-mail.caf | new-mail.caf | MailReceived | |
| 1001 | mail-sent.caf | mail-sent.caf | MailSent | |
| 1002 | Voicemail.caf | Voicemail.caf | VoicemailReceived | |
| 1003 | ReceivedMessage.caf | ReceivedMessage.caf | SMSReceived | |
| 1004 | SentMessage.caf | SentMessage.caf | SMSSent | |
| 1005 | alarm.caf | sq_alarm.caf | CalendarAlert | |
| 1006 | low_power.caf | low_power.caf | LowPower | |
| 1007 | sms-received1.caf | sms-received1.caf | SMSReceived_Alert | |
| 1008 | sms-received2.caf | sms-received2.caf | SMSReceived_Alert | |
| 1009 | sms-received3.caf | sms-received3.caf | SMSReceived_Alert | |
| 1010 | sms-received4.caf | sms-received4.caf | SMSReceived_Alert | |
| 1011 | - | - | SMSReceived_Vibrate | |
| 1012 | sms-received1.caf | sms-received1.caf | SMSReceived_Alert | |
| 1013 | sms-received5.caf | sms-received5.caf | SMSReceived_Alert | |
| 1014 | sms-received6.caf | sms-received6.caf | SMSReceived_Alert | |
| 1015 | Voicemail.caf | Voicemail.caf | - | Available since 2.1 |
| 1016 | tweet_sent.caf | tweet_sent.caf | SMSSent | Available since 5.0 |
| 1020 | Anticipate.caf | Anticipate.caf | SMSReceived_Alert | Available since 4.2 |
| 1021 | Bloom.caf | Bloom.caf | SMSReceived_Alert | Available since 4.2 |
| 1022 | Calypso.caf | Calypso.caf | SMSReceived_Alert | Available since 4.2 |
| 1023 | Choo_Choo.caf | Choo_Choo.caf | SMSReceived_Alert | Available since 4.2 |
| 1024 | Descent.caf | Descent.caf | SMSReceived_Alert | Available since 4.2 |
| 1025 | Fanfare.caf | Fanfare.caf | SMSReceived_Alert | Available since 4.2 |
| 1026 | Ladder.caf | Ladder.caf | SMSReceived_Alert | Available since 4.2 |
| 1027 | Minuet.caf | Minuet.caf | SMSReceived_Alert | Available since 4.2 |
| 1028 | News_Flash.caf | News_Flash.caf | SMSReceived_Alert | Available since 4.2 |
| 1029 | Noir.caf | Noir.caf | SMSReceived_Alert | Available since 4.2 |
| 1030 | Sherwood_Forest.caf | Sherwood_Forest.caf | SMSReceived_Alert | Available since 4.2 |
| 1031 | Spell.caf | Spell.caf | SMSReceived_Alert | Available since 4.2 |
| 1032 | Suspense.caf | Suspense.caf | SMSReceived_Alert | Available since 4.2 |
| 1033 | Telegraph.caf | Telegraph.caf | SMSReceived_Alert | Available since 4.2 |
| 1034 | Tiptoes.caf | Tiptoes.caf | SMSReceived_Alert | Available since 4.2 |
| 1035 | Typewriters.caf | Typewriters.caf | SMSReceived_Alert | Available since 4.2 |
| 1036 | Update.caf | Update.caf | SMSReceived_Alert | Available since 4.2 |
| 1050 | ussd.caf | ussd.caf | USSDAlert | |
| 1051 | SIMToolkitCallDropped.caf | SIMToolkitCallDropped.caf | SIMToolkitTone | |
| 1052 | SIMToolkitGeneralBeep.caf | SIMToolkitGeneralBeep.caf | SIMToolkitTone | |
| 1053 | SIMToolkitNegativeACK.caf | SIMToolkitNegativeACK.caf | SIMToolkitTone | |
| 1054 | SIMToolkitPositiveACK.caf | SIMToolkitPositiveACK.caf | SIMToolkitTone | |
| 1055 | SIMToolkitSMS.caf | SIMToolkitSMS.caf | SIMToolkitTone | |
| 1057 | Tink.caf | Tink.caf | PINKeyPressed | |
| 1070 | ct-busy.caf | ct-busy.caf | AudioToneBusy | There was no category for this sound before 4.0. |
| 1071 | ct-congestion.caf | ct-congestion.caf | AudioToneCongestion | There was no category for this sound before 4.0. |
| 1072 | ct-path-ack.caf | ct-path-ack.caf | AudioTonePathAcknowledge | There was no category for this sound before 4.0. |
| 1073 | ct-error.caf | ct-error.caf | AudioToneError | There was no category for this sound before 4.0. |
| 1074 | ct-call-waiting.caf | ct-call-waiting.caf | AudioToneCallWaiting | There was no category for this sound before 4.0. |
| 1075 | ct-keytone2.caf | ct-keytone2.caf | AudioToneKey2 | There was no category for this sound before 4.0. |
| 1100 | lock.caf | sq_lock.caf | ScreenLocked | |
| 1101 | unlock.caf | sq_lock.caf | ScreenUnlocked | |
| 1102 | - | - | FailedUnlock | |
| 1103 | Tink.caf | sq_tock.caf | KeyPressed | |
| 1104 | Tock.caf | sq_tock.caf | KeyPressed | |
| 1105 | Tock.caf | sq_tock.caf | KeyPressed | |
| 1106 | beep-beep.caf | sq_beep-beep.caf | ConnectedToPower | |
| 1107 | RingerChanged.caf | RingerChanged.caf | RingerSwitchIndication | |
| 1108 | photoShutter.caf | photoShutter.caf | CameraShutter | |
| 1109 | shake.caf | shake.caf | ShakeToShuffle | Available since 3.0 |
| 1110 | jbl_begin.caf | jbl_begin.caf | JBL_Begin | Available since 3.0 |
| 1111 | jbl_confirm.caf | jbl_confirm.caf | JBL_Confirm | Available since 3.0 |
| 1112 | jbl_cancel.caf | jbl_cancel.caf | JBL_Cancel | Available since 3.0 |
| 1113 | begin_record.caf | begin_record.caf | BeginRecording | Available since 3.0 |
| 1114 | end_record.caf | end_record.caf | EndRecording | Available since 3.0 |
| 1115 | jbl_ambiguous.caf | jbl_ambiguous.caf | JBL_Ambiguous | Available since 3.0 |
| 1116 | jbl_no_match.caf | jbl_no_match.caf | JBL_NoMatch | Available since 3.0 |
| 1117 | begin_video_record.caf | begin_video_record.caf | BeginVideoRecording | Available since 3.0 |
| 1118 | end_video_record.caf | end_video_record.caf | EndVideoRecording | Available since 3.0 |
| 1150 | vc~invitation-accepted.caf | vc~invitation-accepted.caf | VCInvitationAccepted | Available since 4.0 |
| 1151 | vc~ringing.caf | vc~ringing.caf | VCRinging | Available since 4.0 |
| 1152 | vc~ended.caf | vc~ended.caf | VCEnded | Available since 4.0 |
| 1153 | ct-call-waiting.caf | ct-call-waiting.caf | VCCallWaiting | Available since 4.1 |
| 1154 | vc~ringing.caf | vc~ringing.caf | VCCallUpgrade | Available since 4.1 |
| 1200 | dtmf-0.caf | dtmf-0.caf | TouchTone | |
| 1201 | dtmf-1.caf | dtmf-1.caf | TouchTone | |
| 1202 | dtmf-2.caf | dtmf-2.caf | TouchTone | |
| 1203 | dtmf-3.caf | dtmf-3.caf | TouchTone | |
| 1204 | dtmf-4.caf | dtmf-4.caf | TouchTone | |
| 1205 | dtmf-5.caf | dtmf-5.caf | TouchTone | |
| 1206 | dtmf-6.caf | dtmf-6.caf | TouchTone | |
| 1207 | dtmf-7.caf | dtmf-7.caf | TouchTone | |
| 1208 | dtmf-8.caf | dtmf-8.caf | TouchTone | |
| 1209 | dtmf-9.caf | dtmf-9.caf | TouchTone | |
| 1210 | dtmf-star.caf | dtmf-star.caf | TouchTone | |
| 1211 | dtmf-pound.caf | dtmf-pound.caf | TouchTone | |
| 1254 | long_low_short_high.caf | long_low_short_high.caf | Headset_StartCall | |
| 1255 | short_double_high.caf | short_double_high.caf | Headset_Redial | |
| 1256 | short_low_high.caf | short_low_high.caf | Headset_AnswerCall | |
| 1257 | short_double_low.caf | short_double_low.caf | Headset_EndCall | |
| 1258 | short_double_low.caf | short_double_low.caf | Headset_CallWaitingActions | |
| 1259 | middle_9_short_double_low.caf | middle_9_short_double_low.caf | Headset_TransitionEnd | |
| 1300 | Voicemail.caf | Voicemail.caf | SystemSoundPreview | |
| 1301 | ReceivedMessage.caf | ReceivedMessage.caf | SystemSoundPreview | |
| 1302 | new-mail.caf | new-mail.caf | SystemSoundPreview | |
| 1303 | mail-sent.caf | mail-sent.caf | SystemSoundPreview | |
| 1304 | alarm.caf | sq_alarm.caf | SystemSoundPreview | |
| 1305 | lock.caf | sq_lock.caf | SystemSoundPreview | |
| 1306 | Tock.caf | sq_tock.caf | KeyPressClickPreview | The category was SystemSoundPreview before 3.2. |
| 1307 | sms-received1.caf | sms-received1.caf | SMSReceived_Selection | |
| 1308 | sms-received2.caf | sms-received2.caf | SMSReceived_Selection | |
| 1309 | sms-received3.caf | sms-received3.caf | SMSReceived_Selection | |
| 1310 | sms-received4.caf | sms-received4.caf | SMSReceived_Selection | |
| 1311 | - | - | SMSReceived_Vibrate | |
| 1312 | sms-received1.caf | sms-received1.caf | SMSReceived_Selection | |
| 1313 | sms-received5.caf | sms-received5.caf | SMSReceived_Selection | |
| 1314 | sms-received6.caf | sms-received6.caf | SMSReceived_Selection | |
| 1315 | Voicemail.caf | Voicemail.caf | SystemSoundPreview | Available since 2.1 |
| 1320 | Anticipate.caf | Anticipate.caf | SMSReceived_Selection | Available since 4.2 |
| 1321 | Bloom.caf | Bloom.caf | SMSReceived_Selection | Available since 4.2 |
| 1322 | Calypso.caf | Calypso.caf | SMSReceived_Selection | Available since 4.2 |
| 1323 | Choo_Choo.caf | Choo_Choo.caf | SMSReceived_Selection | Available since 4.2 |
| 1324 | Descent.caf | Descent.caf | SMSReceived_Selection | Available since 4.2 |
| 1325 | Fanfare.caf | Fanfare.caf | SMSReceived_Selection | Available since 4.2 |
| 1326 | Ladder.caf | Ladder.caf | SMSReceived_Selection | Available since 4.2 |
| 1327 | Minuet.caf | Minuet.caf | SMSReceived_Selection | Available since 4.2 |
| 1328 | News_Flash.caf | News_Flash.caf | SMSReceived_Selection | Available since 4.2 |
| 1329 | Noir.caf | Noir.caf | SMSReceived_Selection | Available since 4.2 |
| 1330 | Sherwood_Forest.caf | Sherwood_Forest.caf | SMSReceived_Selection | Available since 4.2 |
| 1331 | Spell.caf | Spell.caf | SMSReceived_Selection | Available since 4.2 |
| 1332 | Suspense.caf | Suspense.caf | SMSReceived_Selection | Available since 4.2 |
| 1333 | Telegraph.caf | Telegraph.caf | SMSReceived_Selection | Available since 4.2 |
| 1334 | Tiptoes.caf | Tiptoes.caf | SMSReceived_Selection | Available since 4.2 |
| 1335 | Typewriters.caf | Typewriters.caf | SMSReceived_Selection | Available since 4.2 |
| 1336 | Update.caf | Update.caf | SMSReceived_Selection | Available since 4.2 |
| 1350 | - | - | RingerVibeChanged | |
| 1351 | - | - | SilentVibeChanged | |
| 4095 | - | - | Vibrate | There was no category for this sound before 2.2. In the SDK this is the constant kSystemSoundID_Vibrate. |
SystemSoundID myAlertSound;
NSURL *url = [NSURL URLWithString:@"/System/Library/Audio/UISounds/begin_video_record.caf"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &myAlertSound);
AudioServicesPlaySystemSound(myAlertSound);
调用方法二:
NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
if (path) {
SystemSoundID theSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &theSoundID);
if (error == kAudioServicesNoError) {
AudioServicesPlaySystemSound(theSoundID);
}else{
NSLog(@"Failed to create sound ");
}
}
OSX/iOS 播放系统声音的更多相关文章
- iOS播放系统声音和震动
在需要声音的类的.h文件中添加 #import <AudioToolbox/AudioToolbox.h>static SystemSoundID shake_sound_male ...
- iOS 之播放系统声音
导入框架: 代码: #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> @interface MsgPl ...
- iOS调用系统声音与振动
如何调用系统声音?[iphone 调用系统铃声与震动功能] 首先要在工程里加入Audio Toolbox framework这个库,然后在需要调用的文件里#import <AudioToolbo ...
- IOS调用系统声音(键盘声音)
#import <AudioToolbox/AudioToolbox.h> AudioServicesPlaySystemSound(1106); 注:括号中为系统声音的id,详见 htt ...
- iOS 播放系统自带铃声
播放声音代码例子 https://github.com/baitongtong/git-.git 给一个国外网址,苹果系统铃声以及自定义铃声免登陆免费下载:http://www.zedge.net/r ...
- iOS 实现后台 播放音乐声音 AVAudioPlayer 以及铃声设置(循环播放震动)
1.步骤一:在Info.plist中,添加"Required background modes"键,value为:App plays audio 或者: 步骤二: - (BOOL) ...
- iOS系统声音服务(System Sound Services)
系统声音服务(System Sound Services)提供了一个接口,用于播放不超过30秒的声音.它支持的文件格式有限,具体地说只有CAF.AIF和使用PCM或IMA/ADPCM数据的WAV文件. ...
- ios开发——实用技术篇Swift篇&系统声音
系统声音 // MARK: - 系统声音 /*----- 系统声音 ------*/ @IBAction func systemSound() { //建立的SystemSoundID对象 var s ...
- iOS 接收新消息通知调用系统声音 震动
添加系统框架: #import <AudioToolbox/AudioToolbox.h> 调用震动代码: AudioServicesPlaySystemSound(kSystemSoun ...
随机推荐
- Qt限制文本框输入的方法(使用QRegExpValidator,为QLineEdit所独有)
在做界面编程的时候,对文本框的处理往往是个很头疼的事情,一是焦点进入文本框时,从人性化考虑,应选择文本框中文本,方便输入:二是,限制文本框的输入,只允许输入有效的文本,如果不这样做的话,那么就需要在程 ...
- 高级复制实验配置添加复制节点操作时报错:ORA-23308: object GP.T does not exist or is invalid
出错原因: 使用高级复制时,在源端启动复制支持,执行语句:REPADMIN@bys1>execute dbms_repcat.generate_replication_support('gp', ...
- android之ArrayAdapter的重写
昨天介绍了ArrayAdapter的使用,今天介绍一下更加实用的一点,对它进行重写,满足自己的个性化设计需要. ArrayAdapter(数组适配器)一般用于显示一行文本信息,所以比较容易. publ ...
- SQL基础查询实战
总结: 一.单表查询的情况: 1.where.....group by .. Having count(..) 2.Group by haing min(..)条件and max(..)条件(查询最低 ...
- Summer Holiday(强联通入度最小点)
Summer Holiday Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Introduction to Probability (5) Continus random variable
CONTINUOUS RANDOM VARIABLES AND PDFS 连续的随机变量,顾名思义.就是随机变量的取值范围是连续的值,比如汽车的速度.气温.假设我们要利用这些參数来建模.那么就须要引 ...
- Java如何实现对Mysql数据库的行锁
场景如下: 用户账户有余额,当发生交易时,需要实时更新余额.这里如果发生并发问题,那么会造成用户余额和实际交易的不一致,这对公司和客户来说都是很危险的. 那么如何避免: 网上查了下,有 ...
- highcharts图表组件入门教程:如何监听柱状图柱子点击事件动态更新当前数据点数值和所对应X轴刻度
highcharts图表组件入门教程:如何监听柱状图柱子点击事件动态更新当前数据点数值和所对应X轴刻度 作者:highcharts | 时间:2014-6-11 14:07:05 | [小 大] | ...
- LNMP 基于域名的虚拟主机配置 (Centos5.6)
. . server { listen ; #listen [::]: default_server ipv6only=on; server_name www.blog.com; index inde ...
- 数据库比对脚本(PHP版)
$config = [ 'hotfix' => [ 'host'=>'', 'port'=>'', 'account'=>'', 'password'=>'', 'dat ...