zoukankan      html  css  js  c++  java
  • iOS

    Demo下载地址

    iPhone端系统Audio资源路径:/System/Library/Audio/UISounds

    首先,通过 NSFileManager 获取资源路径下的所有路径(文件夹/文件)

        NSFileManager * fileManager = [NSFileManager defaultManager];
        NSURL * _soundDataURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds"];
        NSDirectoryEnumerator * _soundDirectoryEnum = [fileManager enumeratorAtURL:_soundDataURL
                                                        includingPropertiesForKeys:@[NSURLIsDirectoryKey]
                                                                           options:0
                                                                      errorHandler:^BOOL(NSURL * _Nonnull url, NSError * _Nonnull error) {
                                                                          return YES;
                                                                      }];
    

    接着遍历枚举,然后获取系统音频的SoundID:

    /*!
        @typedef        SystemSoundID
        @abstract       SystemSoundIDs are created by the System Sound client application
                        for playback of a provided AudioFile.
    */
    typedef UInt32      SystemSoundID;
    

    通过使用 AudioServicesCreateSystemSoundID 方法:

    /*!
        @function       AudioServicesCreateSystemSoundID
        @abstract       Allows the application to designate an audio file for playback by the System Sound server.
        @discussion     SystemSoundIDs are used passed to
                        AudioServicesPlayAlertSound() & AudioServicesPlaySystemSound(),
                        designating the audio data to be played by the System Sound server.
        @param          inFileURL
                            A CFURLRef for an AudioFile.
        @param          outSystemSoundID
                            Returns a SystemSoundID.
    */
    extern OSStatus 
    AudioServicesCreateSystemSoundID(   CFURLRef                    inFileURL,
                                        SystemSoundID*              outSystemSoundID)
    

    获取SoundID后,最后,使用 AudioServicesPlaySystemSound 播放这个SoundID 音频:
    AudioServicesPlaySystemSound(SystemSoundID inSystemSoundID)

  • 相关阅读:
    洛谷 P2515 [HAOI2010]软件安装
    洛谷 P3818 小A和uim之大逃离 II
    洛谷 P3155 [CQOI2009]叶子的染色
    洛谷 P1414 又是毕业季II
    NOI 2014 起床困难综合征
    NOI 2001 反正切函数的应用
    CF1311E Construct the Binary Tree
    小技巧—卡格式
    CF817F MEX Queries
    洛谷 U138573 序章&第一章 黑暗时代(eviltime)
  • 原文地址:https://www.cnblogs.com/R0SS/p/5590929.html
Copyright © 2011-2022 走看看