zoukankan      html  css  js  c++  java
  • 开启声音

    导入框架:#import <AudioToolbox/AudioToolbox.h>
    - (void)viewDidLoad {
        [super viewDidLoad];
        [self.shake addTarget:self action:@selector(ChangeShake:) forControlEvents:UIControlEventValueChanged];
        [self.sound addTarget:self action:@selector(changeSound:) forControlEvents:UIControlEventValueChanged];
        // Do any additional setup after loading the view from its nib.
    }
    -(void)ChangeShake:(UISwitch *)sender{
        if (self.shake.isOn) {
            NSLog(@"开启状态————震动");
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//系统声音
    //         AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);//警告声音
        }else{
            NSLog(@"关闭状态————震动");
        }
    }
    -(void)changeSound:(UISwitch *)sender{
        if (self.sound.isOn) {
            //播放声音
            NSString *path = [[NSBundle mainBundle] pathForResource:@"message" ofType:@"wav"]; //音效文件路径
            SystemSoundID soundID;//组装并播放音效
            NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
            AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
            AudioServicesPlaySystemSound(soundID);
            AudioServicesDisposeSystemSoundID(soundID);//声音停止
             NSLog(@"开启状态————声音");
        }else{
            NSLog(@"关闭状态————声音");
        }
    }
  • 相关阅读:
    store的应用
    创建简单的SimpleStore
    设置间隔一周的算法
    C#里缓存的使用
    javaFileWrite,FileReader
    javaArrayList
    java函数方法
    java学生管理系统(简易版)
    Tensorflow框架
    java日期
  • 原文地址:https://www.cnblogs.com/conanwin/p/4545691.html
Copyright © 2011-2022 走看看