阿斯顿飞过和


1、引入音频管理文件

#import <AVFoundation/AVFoundation.h>

2、方法抽取

2.1 哈哈

/************ 播放音效 *****************************/
- (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);
}

3、点击按钮播放音效

/************ 点击开关灯按钮就会调用 *****************************/
- (void)OpenOrClosedLamp:(UIButton *)button {
    // 播放音效
    [self playSoundEffect:@"noticeMusic" withType:@"wav"];
}

猜你喜欢

转载自www.cnblogs.com/CH520/p/9344779.html
今日推荐