zoukankan      html  css  js  c++  java
  • System Sounds: Alerts and Sound Effects

    #include <AudioToolbox/AudioToolbox.h>
    #include <CoreFoundation/CoreFoundation.h>
     
    // Define a callback to be called when the sound is finished
    // playing. Useful when you need to free memory after playing.
    static void MyCompletionCallback (
        SystemSoundID  mySSID,
        void * myURLRef
    ) {
            AudioServicesDisposeSystemSoundID (mySSID);
            CFRelease (myURLRef);
            CFRunLoopStop (CFRunLoopGetCurrent());
    }
     
    int main (int argc, const char * argv[]) {
        // Set up the pieces needed to play a sound.
        SystemSoundID    mySSID;
        CFURLRef        myURLRef;
        myURLRef = CFURLCreateWithFileSystemPath (
            kCFAllocatorDefault,
            CFSTR ("../../ComedyHorns.aif"),
            kCFURLPOSIXPathStyle,
            FALSE
        );
     
        // create a system sound ID to represent the sound file
        OSStatus error = AudioServicesCreateSystemSoundID (myURLRef, &mySSID);
     
        // Register the sound completion callback.
        // Again, useful when you need to free memory after playing.
        AudioServicesAddSystemSoundCompletion (
            mySSID,
            NULL,
            NULL,
            MyCompletionCallback,
            (void *) myURLRef
        );
     
        // Play the sound file.
        AudioServicesPlaySystemSound (mySSID);
     
        // Invoke a run loop on the current thread to keep the application
        // running long enough for the sound to play; the sound completion
        // callback later stops this run loop.
        CFRunLoopRun ();
        return 0;
    }
    
  • 相关阅读:
    Mybatis学习记录
    北京信息科技大学第十一届程序设计竞赛E-- kotori和素因子(深搜)
    eclipse快捷键记录
    牛客小白月赛15A 斑羚飞渡
    台州学院第十二届校赛记录(B,C,E,H,I,J,L)
    3.13 模拟赛
    bzoj 4827 礼物
    bzoj 3252 攻略
    bzoj 5457 城市
    bzoj 3681 Arietta
  • 原文地址:https://www.cnblogs.com/ioriwellings/p/4118545.html
Copyright © 2011-2022 走看看