全能型: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);//手機靜音 播放聲音 並震動