美文网首页
App播放短音效

App播放短音效

作者: 水水兔 | 来源:发表于2019-12-20 10:25 被阅读0次

一. 系统音效(短音效播放) 引用

AudioToolbox framework
使用AudioToolbox framework。这个框架可以将比较短的声音注册到 system sound服务上。被注册到system sound服务上的声音称之为 system sounds。它必须满足下面几个条件。
1、 播放的时间不能超过30秒
2、数据必须是 PCM或者IMA4流格式
3、必须被打包成下面三个格式之一:Core Audio Format (.caf), Waveform audio (.wav), 或者 Audio Interchange File (.aiff)
声音文件必须放到设备的本地文件夹下面。通过AudioServicesCreateSystemSoundID方法注册这个声音文件,AudioServicesCreateSystemSoundID需要声音文件的url的CFURLRef对象。

二、具体使用

NSURL *audioPath = [[NSBundle mainBundle] URLForResource:@"in" withExtension:@"caf"];
    // 创建系统声音,同时返回一个ID
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(audioPath), &soundID);
    // Register the sound completion callback.
    AudioServicesAddSystemSoundCompletion(soundID,
                                          NULL, // uses the main run loop
                                          NULL, // uses kCFRunLoopDefaultMode
                                          EMSystemSoundFinishedPlayingCallback, // the name of our custom callback function
                                          NULL // for user data, but we don't need to do that in this case, so we just pass NULL
                                          );
    
    AudioServicesPlaySystemSound(soundID);

震动

// 震动
- (void)playVibration
{
    // Register the sound completion callback.
    AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate,
                                          NULL, // uses the main run loop
                                          NULL, // uses kCFRunLoopDefaultMode
                                          EMSystemSoundFinishedPlayingCallback, // the name of our custom callback function
                                          NULL // for user data, but we don't need to do that in this case, so we just pass NULL
                                          );
    
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}

相关文章

  • App播放短音效

    一. 系统音效(短音效播放) 引用 AudioToolbox framework使用AudioToolbox fr...

  • iOS开始之制作音乐播放器

    一、音频播放与音效播放的基础知识 音效播放 1、音效播放《1》功能介绍用于播放比较短小的音效 常用作系统的提示音...

  • iOS 音频之音效

    音频播放分为: (音频是总称)1、音效播放 (短)、 不需要进行进度、循环等控制 ,AudioToo lBox2...

  • 如何在C语言函数中使用self调用OC的方法

    如题,昨天在做音效播放,顺便吧音效播放的代码记录一下,音效播放的代码如下: 如上在上面音效播放回调的函数里面我需要...

  • 音效 音乐

    播放音效 音效工具类 音乐

  • 音乐播放

    日常开发中所用到的音乐播放 ,除了音乐播放器之外就是音效的播放: 音效播放 音乐播放 音乐播放指的是用音乐播放框架...

  • 音效播放

    一、前言 简单来说,音频可以分为两种: 音效:又称“短音频”,通常在程序中的播放时长为1~2秒,在应用程序中起到点...

  • swift中音频播放与系统音频播放方法的封装

    音效,又称“短音频”,通常在程序中的播放时长为1~2秒,在APP开发的过程中添加音效,经常能起到点缀效果,提升整体...

  • iOS App内短音效设置

    一. 系统音效(短音效播放)AudioToolbox framework使用AudioToolbox framew...

  • UI(三十七)音效、音频、录音

    *1、播放 (1)音效播放 《1》功能介绍:播放比较短的音音效,常用于做系统提示音使用到的框架(AudioTool...

网友评论

      本文标题:App播放短音效

      本文链接:https://www.haomeiwen.com/subject/rfpbnctx.html