zoukankan      html  css  js  c++  java
  • 音效

    -(void) initWithYinxiao{
        NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:@"清碎.wav" withExtension:nil];
        //1.获得系统声音ID
        SystemSoundID soundID=0;
        /**
         * inFileUrl:音频文件url
         * outSystemSoundID:声音id(此函数会将音效文件加入到系统音频服务中并返回一个长整形ID)
         */
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileUrl), &soundID);
        //如果需要在播放完之后执行某些操作,可以调用如下方法注册一个播放完成回调函数
        AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, soundCompleteCallback, NULL);
        //2.播放音频
        AudioServicesPlaySystemSound(soundID);//播放音效
        //    AudioServicesPlayAlertSound(soundID);//播放音效并震动
        //3.销毁声音
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //        AudioServicesDisposeSystemSoundID(soundID);
    //    });
        //  AudioServicesDisposeSystemSoundID(soundID);
    }
     [self initWithYinxiao];

     头文件 :

    import <AudioToolbox/AudioToolbox.h>

  • 相关阅读:
    二分图的部分关系
    二分图的部分关系
    日常训练赛 Problem C – Complete Naebbirac’s sequence
    日常训练赛 Problem C – Complete Naebbirac’s sequence
    J
    J
    Python strip()方法
    Python startswith()方法
    Python splitlines()方法
    Python split()方法
  • 原文地址:https://www.cnblogs.com/sheer-code/p/10732350.html
Copyright © 2011-2022 走看看