系統音&警告音&震動,萌化系統音

來源:互聯網
上載者:User

系統音&警告音&震動,萌化系統音

為了引起使用者注意發出警告的時候,常常伴隨有提示音震動等.系統聲音服務提供了一個介面,用於播放不超過30秒的音效檔,他支援的格式有CAF,AIF,WAV.

iOS使用該API支援3種不同的通知:

聲音:立刻播放一個簡單的音效檔,如果手機為靜音,使用者什麼什麼都聽不到.

提醒:播放音效檔,如果手機設定為靜音或震動,將通過震動提醒使用者

震動:震動手機,不考慮其他設定

 

首先匯入架構:AudioToolbox ,在檔案中匯入該架構的借口檔案:#import<AudioToolbox/AudioToolbox.h>

在xib檔案中添加三個按鈕,分別實現以上三個功能.放入一個WAV格式的音效檔

//聲音

- (IBAction)buttonClick:(UIButton *)sender {    //警告音一般較短    //聲明變數soundid,用來引入音樂檔案    SystemSoundID soundid;    //得到音效檔路徑    NSString *soundfile=[[NSBundle mainBundle]pathForResource:@"soundeffect" ofType:@"wav"];    //1.指向檔案位置的CFURLRef. 2.指標    //__bridge.將C語言結構轉化為OC語言對象    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundfile], &soundid);    //播放警告音    AudioServicesPlaySystemSound(soundid);}

//提醒

- (IBAction)alertButtonClick:(UIButton *)sender {    SystemSoundID soundid;    NSString *soundfile=[[NSBundle mainBundle]pathForResource:@"soundeffect" ofType:@"wav"];    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundfile], &soundid);    //警告音,當使用者調整為靜音時震動    AudioServicesPlayAlertSound(soundid);}

//震動

//震動- (IBAction)shakeButtonClick:(UIButton *)sender {    SystemSoundID soundid;    //不論手機狀態,只有震動    AudioServicesPlaySystemSound(soundid);}

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.