标签:file def isa 二维码 The void SM elf 变量
引入音频管理文件
#import <AVFoundation/AVFoundation.h>
typedef NS_ENUM(NSInteger, VoiceType) {
VoiceTypeIsWav = 0, // wav
VoiceTypeIsMp3 = 1, // mp3
VoiceTypeIsAPE = 2, // ape
VoiceTypeIsOther = 3 // 其他
};
NSString *const VoiceTypeStringMap[] = {
[VoiceTypeIsWav] = @"wav",
[VoiceTypeIsMp3] = @"mp3",
[VoiceTypeIsAPE] = @"ape",
[VoiceTypeIsOther] = @"Other"
};
/************ 播放音效 *****************************/
- (void)playSoundEffect:(NSString *)name withType:(VoiceType)type {
// 播放扫描二维码的声音
SystemSoundID soundID;
NSString *strSoundFile = [[NSBundle mainBundle] pathForResource:name ofType:VoiceTypeStringMap[type]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:strSoundFile],&soundID);
AudioServicesPlaySystemSound(soundID);
}
/************ 点击开关灯按钮就会调用 *****************************/
- (void)OpenOrClosedLamp:(UIButton *)button {
// 播放音效
[self playSoundEffect:@"btn_press_voice_2" withType:VoiceTypeIsWav];
}
标签:file def isa 二维码 The void SM elf 变量
原文地址:https://www.cnblogs.com/CH520/p/9243722.html