iOS系统声音列表
效果
说明
1. 点击cell就能发出声音
2. 只需要给出声音编号,就可以,非常简单易用
源码
https://github.com/YouXianMing/iOS-Utilities
// // SystemSound.h // SystemSound // // Created by YouXianMing on 15/8/24. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import <Foundation/Foundation.h> #import "SoundInfomation.h" @interface SystemSound : NSObject /** * 获取系统消息列表 */ + (void)accessSystemSoundsList; /** * 系统声音的列表 * * @return SoundInfomation对象数组 */ + (NSArray *)systemSounds; /** * 播放声音 * * @param sound 声音 */ + (void)playWithSound:(SoundInfomation *)sound; /** * 根据声音ID号播放声音 * * @param soundID 声音ID号码 */ + (void)playWithSoundID:(UInt32)soundID; @end
// // SystemSound.m // SystemSound // // Created by YouXianMing on 15/8/24. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import "SystemSound.h" #import <AudioToolbox/AudioToolbox.h> static NSMutableArray *_systemSounds = nil; @implementation SystemSound + (void)accessSystemSoundsList { static dispatch_once_t predicate; dispatch_once(&predicate, ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSMutableArray *audioFileList = [NSMutableArray array]; _systemSounds = [NSMutableArray array]; // 读取文件系统 NSFileManager *fileManager = [[NSFileManager alloc] init]; NSURL *directoryURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds"]; NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey]; NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtURL:directoryURL includingPropertiesForKeys:keys options:0 errorHandler:^(NSURL *url, NSError *error) { return YES; }]; for (NSURL *url in enumerator) { NSError *error; NSNumber *isDirectory = nil; if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) { } else if (![isDirectory boolValue]) { [audioFileList addObject:url]; SystemSoundID soundID; AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)url, &soundID); SoundInfomation *sound = [[SoundInfomation alloc] init]; sound.soundID = soundID; sound.soundUrl = url; sound.soundName = url.lastPathComponent; [_systemSounds addObject:sound]; } } // 读取文件 NSString *path = [[NSBundle mainBundle] pathForResource:@"SystemSoundList" ofType:nil]; NSData *data = [[NSData alloc] initWithContentsOfFile:path]; NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSArray *array = [string componentsSeparatedByString:@" "]; for (int i = 0; i < array.count; i++) { NSString *tmp = array[i]; NSArray *soundInfo = [tmp componentsSeparatedByString:@" "]; SoundInfomation *sound = [[SoundInfomation alloc] init]; sound.soundID = (unsigned int)[soundInfo[0] integerValue]; sound.soundName = soundInfo[1]; [_systemSounds addObject:sound]; } }); }); } + (NSArray *)systemSounds { return _systemSounds; } + (void)playWithSound:(SoundInfomation *)sound { AudioServicesPlaySystemSound(sound.soundID); } + (void)playWithSoundID:(UInt32)soundID { AudioServicesPlaySystemSound(soundID); } @end
// // SoundInfomation.h // SystemSound // // Created by YouXianMing on 15/8/24. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import <Foundation/Foundation.h> @interface SoundInfomation : NSObject /** * 系统声音编号(必须有) */ @property (nonatomic) UInt32 soundID; /** * 系统声音地址 */ @property (nonatomic, strong) NSURL *soundUrl; /** * 声音的名字 */ @property (nonatomic, strong) NSString *soundName; @end
// // SoundInfomation.m // SystemSound // // Created by YouXianMing on 15/8/24. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import "SoundInfomation.h" @implementation SoundInfomation @end
1000 new-mail.caf MailReceived 1001 mail-sent.caf MailSent 1002 Voicemail.caf VoicemailReceived 1003 ReceivedMessage.caf SMSReceived 1004 SentMessage.caf SMSSent 1005 alarm.caf CalendarAlert 1006 low_power.caf LowPower 1007 sms-received1.caf SMSReceived_Alert 1008 sms-received2.caf SMSReceived_Alert 1009 sms-received3.caf SMSReceived_Alert 1010 sms-received4.caf SMSReceived_Alert 1011 - SMSReceived_Vibrate 1012 sms-received1.caf SMSReceived_Alert 1013 sms-received5.caf SMSReceived_Alert 1014 sms-received6.caf SMSReceived_Alert 1015 Voicemail.caf - 1016 tweet_sent.caf SMSSent 1020 Anticipate.caf SMSReceived_Alert 1021 Bloom.caf SMSReceived_Alert 1022 Calypso.caf SMSReceived_Alert 1023 Choo_Choo.caf SMSReceived_Alert 1024 Descent.caf SMSReceived_Alert 1025 Fanfare.caf SMSReceived_Alert 1026 Ladder.caf SMSReceived_Alert 1027 Minuet.caf SMSReceived_Alert 1028 News_Flash.caf SMSReceived_Alert 1029 Noir.caf SMSReceived_Alert 1030 Sherwood_Forest.caf SMSReceived_Alert 1031 Spell.caf SMSReceived_Alert 1032 Suspense.caf SMSReceived_Alert 1033 Telegraph.caf SMSReceived_Alert 1034 Tiptoes.caf SMSReceived_Alert 1035 Typewriters.caf SMSReceived_Alert 1036 Update.caf SMSReceived_Alert 1050 ussd.caf USSDAlert 1051 SIMToolkitCallDropped.caf SIMToolkitTone 1052 SIMToolkitGeneralBeep.caf SIMToolkitTone 1053 SIMToolkitNegativeACK.caf SIMToolkitTone 1054 SIMToolkitPositiveACK.caf SIMToolkitTone 1055 SIMToolkitSMS.caf SIMToolkitTone 1057 Tink.caf PINKeyPressed 1070 ct-busy.caf AudioToneBusy 1071 ct-congestion.caf AudioToneCongestion 1072 ct-path-ack.caf AudioTonePathAcknowledge 1073 ct-error.caf AudioToneError 1074 ct-call-waiting.caf AudioToneCallWaiting 1075 ct-keytone2.caf AudioToneKey2 1100 lock.caf ScreenLocked 1101 unlock.caf ScreenUnlocked 1102 - FailedUnlock 1103 Tink.caf KeyPressed 1104 Tock.caf KeyPressed 1105 Tock.caf KeyPressed 1106 beep-beep.caf ConnectedToPower 1107 RingerChanged.caf RingerSwitchIndication 1108 photoShutter.caf CameraShutter 1109 shake.caf ShakeToShuffle 1110 jbl_begin.caf JBL_Begin 1111 jbl_confirm.caf JBL_Confirm 1112 jbl_cancel.caf JBL_Cancel 1113 begin_record.caf BeginRecording 1114 end_record.caf EndRecording 1115 jbl_ambiguous.caf JBL_Ambiguous 1116 jbl_no_match.caf JBL_NoMatch 1117 begin_video_record.caf BeginVideoRecording 1118 end_video_record.caf EndVideoRecording 1150 vc~invitation-accepted.caf VCInvitationAccepted 1151 vc~ringing.caf VCRinging 1152 vc~ended.caf VCEnded 1153 ct-call-waiting.caf VCCallWaiting 1154 vc~ringing.caf VCCallUpgrade 1200 dtmf-0.caf TouchTone 1201 dtmf-1.caf TouchTone 1202 dtmf-2.caf TouchTone 1203 dtmf-3.caf TouchTone 1204 dtmf-4.caf TouchTone 1205 dtmf-5.caf TouchTone 1206 dtmf-6.caf TouchTone 1207 dtmf-7.caf TouchTone 1208 dtmf-8.caf TouchTone 1209 dtmf-9.caf TouchTone 1210 dtmf-star.caf TouchTone 1211 dtmf-pound.caf TouchTone 1254 long_low_short_high.caf Headset_StartCall 1255 short_double_high.caf Headset_Redial 1256 short_low_high.caf Headset_AnswerCall 1257 short_double_low.caf Headset_EndCall 1258 short_double_low.caf Headset_CallWaitingActions 1259 middle_9_short_double_low.caf Headset_TransitionEnd 1300 Voicemail.caf SystemSoundPreview 1301 ReceivedMessage.caf SystemSoundPreview 1302 new-mail.caf SystemSoundPreview 1303 mail-sent.caf SystemSoundPreview 1304 alarm.caf SystemSoundPreview 1305 lock.caf SystemSoundPreview 1306 Tock.caf KeyPressClickPreview 1307 sms-received1.caf SMSReceived_Selection 1308 sms-received2.caf SMSReceived_Selection 1309 sms-received3.caf SMSReceived_Selection 1310 sms-received4.caf SMSReceived_Selection 1311 - SMSReceived_Vibrate 1312 sms-received1.caf SMSReceived_Selection 1313 sms-received5.caf SMSReceived_Selection 1314 sms-received6.caf SMSReceived_Selection 1315 Voicemail.caf SystemSoundPreview 1320 Anticipate.caf SMSReceived_Selection 1321 Bloom.caf SMSReceived_Selection 1322 Calypso.caf SMSReceived_Selection 1323 Choo_Choo.caf SMSReceived_Selection 1324 Descent.caf SMSReceived_Selection 1325 Fanfare.caf SMSReceived_Selection 1326 Ladder.caf SMSReceived_Selection 1327 Minuet.caf SMSReceived_Selection 1328 News_Flash.caf SMSReceived_Selection 1329 Noir.caf SMSReceived_Selection 1330 Sherwood_Forest.caf SMSReceived_Selection 1331 Spell.caf SMSReceived_Selection 1332 Suspense.caf SMSReceived_Selection 1333 Telegraph.caf SMSReceived_Selection 1334 Tiptoes.caf SMSReceived_Selection 1335 Typewriters.caf SMSReceived_Selection 1336 Update.caf SMSReceived_Selection 1350 - RingerVibeChanged 1351 - SilentVibeChanged 4095 - Vibrate