iOS 播放短音效
2021-07-28 本文已影响0人
山杨
SystemSoundID soundID;
//获取音频文件路径
NSString *soundPath = [NSBundle.mainBundle pathForResource:@"xx.caf" ofType:nil];
// 本地音频文件URL
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL, & soundID);// 加载音频
if (error) {
NSLog(@"error : %@", @(error));
return;
}
AudioServicesPlaySystemSound(soundID);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
备注:
销毁 SoundID
AudioServicesDisposeSystemSoundID(soundID);