【iOS】播放按钮点击音效

有点击按钮产生音效的需求

/**
 设置签到音效
 @param name 音效名称
 @param soundtype 音效类型
 @param playtype 播放类型
 */
-(void)playSoundWithName:(NSString *)name soundtype:(NSString *)soundtype playtype:(PlaySoundType)playtype
{
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:name ofType:soundtype];
    NSURL *soundUrl = [NSURL fileURLWithPath:soundPath];
    
    //生成音效
    SystemSoundID soundID = 0;
    AudioServicesCreateSystemSoundID((__bridge  CFURLRef) (soundUrl), &soundID);
    // 开始播放音效
    playtype?(AudioServicesPlayAlertSound(soundID)):(AudioServicesPlaySystemSound(soundID));
    
   /**
    //普通音效
    void AudioServicesPlaySystemSound(SystemSoundID   inSystemSoundID);
    // 开始播放音效并带震动
    void AudioServicesPlayAlertSound(SystemSoundID inSystemSoundID);
    */
}

这是代码中的枚举类型,主要用来选择播放的方式,normal是普通播放,shake是震动

typedef NS_ENUM(NSInteger, PlaySoundType) {
    PlaySoundTypeNormal = 0,
    PlaySoundTypeShake,
};
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值