iOS音效,ios音效外掛程式

來源:互聯網
上載者:User

iOS音效,ios音效外掛程式

//AudioToolbox.framework是一套基於C語言的架構,使用它來播放音效其本質是將短音頻註冊到系統聲音服務(System Sound Service)//System Sound Service的限制://1.音頻播放時間不能超過30s//2.資料必須是PCM或者IMA4格式//3.音頻檔案必須打包成.caf、.aif、.wav中的一種(注意這是官方文檔的說法,實際測試發現一些.mp3也可以播放)

播放音訊方法:

/** *  播放完成回呼函數 * *  @param soundID    系統聲音ID *  @param clientData 回調時傳遞的資料 */void soundCompleteCallback(SystemSoundID soundID,void * clientData){    NSLog(@"播放完成...");}/** *  播放音效檔案 * *  @param name 音頻檔案名稱 */-(void)playSoundEffect:(NSString *)name{    NSString *audioFile=[[NSBundle mainBundle] pathForResource:name ofType:nil];    NSLog(@"%@",audioFile);    NSURL *fileUrl=[NSURL fileURLWithPath:audioFile];    //1.獲得系統聲音ID    SystemSoundID soundID=0;    /**     * inFileUrl:音頻檔案url     * outSystemSoundID:聲音id(此函數會將音效檔案加入到系統音頻服務中並返回一個長整形ID)     */    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileUrl), &soundID);    //如果需要在播放完之後執行某些操作,可以調用如下方法註冊一個播放完成回呼函數    AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, soundCompleteCallback, NULL);    //2.播放音頻    AudioServicesPlaySystemSound(soundID);//播放音效    //    AudioServicesPlayAlertSound(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.