最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IOS 播放系統(tǒng)提示音使用總結(jié)(AudioToolbox)

 更新時間:2017年05月16日 11:38:43   投稿:lqh  
這篇文章主要介紹了IOS 播放系統(tǒng)提示音使用總結(jié)(AudioToolbox)的相關(guān)資料,需要的朋友可以參考下

IOS 播放系統(tǒng)提示音使用總結(jié)(AudioToolbox)

開發(fā)過程中需要用到蘋果自帶的系統(tǒng)提示音,下面我總結(jié)了一下關(guān)于系統(tǒng)提示音播放的方法

第一步首先得導(dǎo)入AudioToolbox框架

#import <AudioToolbox/AudioToolbox.h>

播放系統(tǒng)自帶的提示聲

播放系統(tǒng)自帶的提示聲很簡單,只需要兩行代碼就能搞定了:

//定義一個SystemSoundID
 SystemSoundID soundID = 1000;//具體參數(shù)詳情下面貼出來
 //播放聲音
 AudioServicesPlaySystemSound(soundID);

關(guān)于SystemSoundID的相關(guān)參數(shù)介紹和系統(tǒng)所有的鈴聲的介紹

播放自定義的提示聲,既有聲音也帶振動

- (void)playNotifySound {
 //獲取路徑
 NSString *path = [[NSBundle mainBundle] pathForResource:@"candoNotifySound" ofType:@"mp3"];
 //定義一個SystemSoundID
 SystemSoundID soundID;
 //判斷路徑是否存在
 if (path) {
  //創(chuàng)建一個音頻文件的播放系統(tǒng)聲音服務(wù)器
  OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)([NSURL fileURLWithPath:path]), &soundID);
  //判斷是否有錯誤
  if (error != kAudioServicesNoError) {
   NSLog(@"%d",(int)error);
  }
 }
 //播放聲音和振動
 AudioServicesPlayAlertSoundWithCompletion(soundID, ^{
  //播放成功回調(diào)
 });
}

只有振動沒有聲音

 //手機只振動沒聲音
 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

只有聲音不帶振動

//必須得是自定義的聲音,經(jīng)過測試系統(tǒng)的聲音好像都帶振動
- (void)playNotifySound {
 //獲取路徑
 NSString *path = [[NSBundle mainBundle] pathForResource:@"candoNotifySound" ofType:@"mp3"];
 //定義一個帶振動的SystemSoundID
 SystemSoundID soundID = 1000;
 //判斷路徑是否存在
 if (path) {
  //創(chuàng)建一個音頻文件的播放系統(tǒng)聲音服務(wù)器
  OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)([NSURL fileURLWithPath:path]), &soundID);
  //判斷是否有錯誤
  if (error != kAudioServicesNoError) {
   NSLog(@"%d",(int)error);
  }
 }
 //只播放聲音,沒振動
 AudioServicesPlaySystemSound(soundID);
}

上面是我關(guān)于提示聲使用的一些技巧,希望大家能學到東西,如果有不足希望大家給予補充,謝謝閱讀!

相關(guān)文章

最新評論

横山县| 大邑县| 宜昌市| 乳源| 桃园市| 新建县| 普格县| 乌拉特中旗| 贡觉县| 横山县| 拜城县| 万山特区| 昂仁县| 合江县| 溧水县| 图木舒克市| 潮州市| 平邑县| 射阳县| 遵化市| 合江县| 绥芬河市| 和林格尔县| 富阳市| 旌德县| 兴海县| 宁都县| 收藏| 高雄县| 嘉禾县| 德令哈市| 张家界市| 商城县| 昔阳县| 城口县| 吉隆县| 包头市| 台南县| 子长县| 宕昌县| 陕西省|