三、Audio 系統聲音

全能型:AVFoundation

編解碼:AudiotoolBox

底層:AudioUnit

3D: openAL

控制類VC:mediaPlayer

Audio systemsound

播放震動效果
播放系統音樂效果
播放提示音效果

震動效果:
NSString *device = [UIDevice currentDevice]model];
if (device isEqualToString:@”iPhone”){
AudioServicesPlaySystemSound(kSystemSoundID_vibrate);
}else{
提示
}

提示音:
//播放系統聲音
- (void)playSystemSound{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@”music” ofType:@”car”];
if (!filePath) {
return;
}
NSURL *url = [NSURL fileURLWithPath:filePath];
//
SystemSoundID system_id;
//綁定ID 和 URL
AudioServicesCreateSystemSoundID((__bridge CFURLRef) url, &system_id);

//註冊回調
AudioServicesAddSystemSoundCompletion(system_id, NULL, NULL, AudioServicesSystemSoundFinish, NULL);
//播放
AudioServicesPlaySystemSound(system_id);

}

@end

void
AudioServicesSystemSoundFinish( SystemSoundID ssID,
void* __nullable clientData){
AudioServicesRemoveSystemSoundCompletion(ssID);
AudioServicesDisposeSystemSoundID(ssID);//手機靜音的時候無效

}

播放提示音
NSString *filePath = [[NSBundle mainBundle] pathForResource:@”music” ofType:@”car”];
if (!filePath) {
return;
}
NSURL *url = [NSURL fileURLWithPath:filePath];
//
SystemSoundID system_id;
//綁定ID 和 URL
AudioServicesCreateSystemSoundID((__bridge CFURLRef) url, &system_id);

//註冊回調
AudioServicesAddSystemSoundCompletion(system_id, NULL, NULL, AudioServicesSystemSoundFinish, NULL);
//播放
AudioServicesPlaySystemSound(system_id);

AudioServicesPlayAlertSound(system_id);//手機靜音 播放聲音 並震動
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章