ios 调用系统提示音教程

本文详细介绍了在iOS项目中通过引入AudioToolbox框架并使用AudioServicesPlaySystemSound方法来调用系统自带提示音的方法,并提供了一个方便测试系统声音的Demo。此外,还附上了系统提示音对应的列表,帮助开发者快速定位和使用所需的提示音。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目前做的一个项目里用到了提示音,但是又不想添加提示音到库里,便开始研究调用系统自带的提示音,最后终于找到了。

开始在CC上查发现好像很多人都在问,但没人回答,我就把自己查到的东西和写的一个demo给大家分享下吧

首先要在工程里加入Audio Toolbox framework这个库,然后在需要调用的文件里#import <AudioToolbox/AudioToolbox.h>

最后在需要播放提示音的地方写上
AudioServicesPlaySystemSound(1106); 
注:括号中为系统声音的id,详见最下面的列表。

为了方便大家测试系统声音,我写了一个demo供大家使用下载。

另外,如果想用自己的音频文件创建系统声音来播放的同学可以参考如下代码。

//Get the filename of the sound file:
NSString *path = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], @"/jad0007a.wav"];

//declare a system sound
id SystemSoundID soundID;

//Get a URL for the sound file
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

//Use audio sevices to create the sound
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
//Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);

顺便附上系统提示音对应的列表

AudioServices

AudioServices is a group of C functions in AudioToolbox for playing short (≤30 seconds) sounds.

Predefined sounds

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/.

kSystemSoundID_Vibrate.


原文来自: http://www.blogjava.net/writegull/archive/2012/04/16/374729.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值