IOS audiosession 会话控制声音播放

今天遇到一个问题:

当我外部想要关闭声音播放的时候 audiosessionsetActive(false)

居然报错了,但是作用起了  AVAudioSessionErrorCodeIsBusy: 560030580

有人说是重复操作,确认了下并没有

看到简书上有人说这个问题,属正常

http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed19fa950d100b92235c438014648c83493e8ed45f93130a1c187ba1a674751a02d2c6786752fe1e5ffeb56b32610c73f38cc9f8199aedc97538895775275dc71a4f8f0eaebb1165817dd04de8df48baeca72592de89928f131281&p=b46fc64ad4af02ff57ee94797f079c&newp=882a9645d18218f404a2c7710f4b94231610db2151dcd701298ffe0cc4241a1a1a3aecbf23221204d8cf786304aa425ceaf43d723d0034f1f689df08d2ecce7e6ed17c683f&user=baidu&fm=sc&query=AVAudioSessionErrorCodeIsBusy&qid=b5e7ae130000b06c&p1=2

注意:

如果一个活动音频会话的优先级高于当前音频会话(如电话呼叫),并且两个音频会话都不允许混音,则激活音频会话将失败。
取消激活正在运行音频对象的音频会话,将停止正在运行的运行对象并取消激活会话,error 返回 AVAudioSessionErrorCodeIsBusy错误。(虽然报错,但是活动状态扔被更改成功为未激活)。

附上 audioSESSION常见错误码:

 {
AVAudioSessionErrorCodeNone = 0,
AVAudioSessionErrorCodeMediaServicesFailed = 'msrv', /* 0x6D737276, 1836282486 */
AVAudioSessionErrorCodeIsBusy = '!act', /* 0x21616374, 560030580 */
AVAudioSessionErrorCodeIncompatibleCategory = '!cat', /* 0x21636174, 560161140 */
AVAudioSessionErrorCodeCannotInterruptOthers = '!int', /* 0x21696E74, 560557684 */
AVAudioSessionErrorCodeMissingEntitlement = 'ent?', /* 0x656E743F, 1701737535 */
AVAudioSessionErrorCodeSiriIsRecording = 'siri', /* 0x73697269, 1936290409 */
AVAudioSessionErrorCodeCannotStartPlaying = '!pla', /* 0x21706C61, 561015905 */
AVAudioSessionErrorCodeCannotStartRecording = '!rec', /* 0x21726563, 561145187 */
AVAudioSessionErrorCodeBadParam = -50,
AVAudioSessionErrorInsufficientPriority = '!pri', /* 0x21707269, 561017449 */
AVAudioSessionErrorCodeResourceNotAvailable = '!res', /* 0x21726573, 561145203 */
AVAudioSessionErrorCodeUnspecified = 'what' /* 0x77686174, 2003329396 */
} NS_AVAILABLE_IOS(7_0); 苹果官方有写:
————————————————————————————————————————————————————————————————————————————
Instance Method

setActive:withOptions:error:

Activates or deactivates your app’s audio session using the specified options.

SDKs

  • iOS 6.0+
  • tvOS 9.0+
  • watchOS 2.0+

Framework

  • AVFoundation

Declaration

- (BOOL)setActive:(BOOL)active
withOptions:(AVAudioSessionSetActiveOptions)options
error:(NSError * _Nullable *)outError;

Parameters

active

Specify YES to activate your app’s audio session, or NO to deactivate it.

options

An integer bit mask containing one or more constants from the AVAudioSessionSetActiveOptions enumeration.

outError

On input, a pointer to an error object. If an error occurs, the pointer is set to an NSErrorobject that describes the error. If you do not want error information, pass in nil.

Return Value

YES if the session’s active state was changed successfully, or NO if it was not.

Discussion

If another active audio session has higher priority than yours (for example, a phone call), and neither audio session allows mixing, attempting to activate your audio session fails. Deactivating an audio session that has running audio objects will stop the running audio objects, deactivate the session, and a AVAudioSessionErrorCodeIsBusy error will be returned.

Note

When deactivating a session, the return value is falseExpression but the active state will change to deactivate.

Topics

Data Types

AVAudioSessionSetActiveOptions

A flag that provides additional information about your app’s audio intentions upon session deactivation.

See Also

Activating the Audio Session

- setActive:error:

Activates or deactivates your app’s audio session.

- activateWithOptions:completionHandler:

Asynchronously activates an audio session on watchOS.



AudiosessionSetActive的更多相关文章

  1. 一篇对iOS音频比较完善的文章

    转自:http://www.cnblogs.com/iOS-mt/p/4268532.html 感谢作者:梦想通 前言 从事音乐相关的app开发也已经有一段时日了,在这过程中app的播放器几经修改我也 ...

  2. [ios]app后台运行

    参考:http://www.douban.com/note/375127736/ 1 使用开源代码MMPDeepSleepPreventer将文件加入工程,包括音频文件.可以在源文件中加入单例,便于使 ...

  3. iOS编程修改系统音量

    iOS的AVFoundation框架提供了基本的音视频播放工具,我们基本上可以靠其中提供的类完成绝大部分的音视频播放任务.但是在音频播放的输出音量的处理上,苹果的策略比较保守.尽管AVPlayer和A ...

  4. iOS调节系统音量

    目录[-] 使用MPVolumeView 编程实现系统音量调节2 通过MPVolumeSlider的实例来操作系统音量 有问题!我不喜欢系统弹出音量提示 还有问题,我修改了系统音量但是不是通过我的UI ...

  5. IOS 音频播放

    iOS音频播放 (一):概述 前言 从事音乐相关的app开发也已经有一段时日了,在这过程中app的播放器几经修改我也因此对于iOS下的音频播放实现有了一定的研究.写这个系列的博客目的一方面希望能够抛砖 ...

  6. iOS音频播放(二):AudioSession

    (本文转自码农人生) 前言 在实施前一篇中所述的7个步骤步之前还必须面对一个麻烦的问题,AudioSession.   AudioSession简介 AudioSession这个玩意的主要功能包括以下 ...

  7. iOS 监听声音按键

    有时在项目中需要监听用户是否按下了物理声音键,然后来做某些操作,如:你自定义了一个照相功能,希望用户按下声音按键时也能进行拍照,苹果自带的照相机就有这种功能. 监听物理声音键是否按下的方法有很多中,我 ...

  8. DOUAudioStreamer 中kqueue的应用

    DOUAudioStreamer是一个基于Core Audio的流式音频播放器,其中的DOUAudioEventLoop通过kqueue来控制音频的各种状态. kqueue简介(详情请看官方manua ...

  9. iOS录音后播放声音小,AudioSessionInitialize failed,AudioQueueStart failed (-50)

    方法1: UInt32 audioRoute = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty(kAudioSess ...

随机推荐

  1. 前端基础----CSS语法、CSS四种引入方式、CSS选择器、CSS属性操作

    一.CSS语法 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如: h1 {color:red; font-size:14px;} 二.CSS四种引入方式 1,行内式 行内式是在标 ...

  2. 深入学习Motan系列(五)—— 序列化与编码协议

    一.序列化 1.什么是序列化和反序列化? 序列化:将对象变成有序的字节流,里面保存了对象的状态和相关描述信息. 反序列化:将有序的字节流恢复成对象. 一句话来说,就是对象的保存与恢复. 为什么需要这个 ...

  3. 一篇讲解如何调试pg 扩展的文章

    以下链接这片关于pg 扩展调试的文章挺不错,记录下 http://big-elephants.com/2015-10/writing-postgres-extensions-part-iii/     ...

  4. 算法图解 (Aditya Bhargava 著)

    第1章 算法简介第2章 选择排序第3章 递归第4章 快速排序第5章 散列表第6章 广度优先搜索第7章 狄克斯特拉算法第8章 贪婪算法第9章 动态规划第10章 K最近邻算法第11章 接下来如何做 第1章 ...

  5. 第一章 HTML+CSS(中)

    4.域元素(form表单.textarea文本域.fieldset域集合.input使用) 案例 表单 用户名: 密码: 昵称: 你喜欢的水果有? 苹果 黄瓜 香蕉 请选择性别 男 女 请选择你要的网 ...

  6. 十六、springcloud(二)Eureka集群

    1.创建子工程spring-cloud-peer(jar) 2.创建application-peer1.properties,application-peer2.properties applicat ...

  7. myibatis的坑--text类型的字段查询缺失

    问题:某个字段的类型为text(或者mediumtext,longtext)的时候,用selectByQuery语句查询出来的结果不包含该字段内容. myibatis 用mybatis-generat ...

  8. centos7.4 64位安装 google-chrome 与 chromedriver 运行 Python selenium 项目

    centos7.4 实例 利用 yum 命令安装 google-chrome 超级简单(安装最新版): yum install https://dl.google.com/linux/direct/g ...

  9. FPGA 中三角函数的实现

    FPGA 中三角函数的实现

  10. debian下arp欺骗

    sudo sysctl -w net.ipv4.ip_forward= sudo sysctl -p arpspoof -i eth0 -t 目标ip -r 伪装ip或者ettercap -i eth ...