調用系統提示音教程

論壇會員zhaoxy2850分享的關於調用系統提示音的教程,寫的很詳細

目前做的一個項目裏用到了提示音,但是又不想添加提示音到庫裏,便開始研究調用系統自帶的提示音,最後終於找到了。

開始在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);


順便附上系統提示音對應的列表
http://iphonedevwiki.net/index.php/AudioServices

希望能對大家有幫助吧~ 

http://www.cocoachina.com/bbs/job.php?action=download&aid=30581

發佈了7 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章