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. Python服务Dokcer化并k8s部署实例

    这篇文章记录了我试验将一个基于python的服务docker化并k8s部署的过程. 服务介绍Docker化设计业务代码改造创建docker镜像K8S部署设计yaml文件运行服务介绍这是一个用 pyth ...

  2. ASP.NET 4.0 :MasterPage母版页的ClientIDMode属性

    在ASP.NET 4.0之前我们总是要为控件的ClientID头疼,比如明明一个叫lblName的Label放在一个叫做grd的GridView里面后,在页面上改Label的ID就变成了诸如grd_c ...

  3. Python完全新手教程

    转发:作者: taowen  来源: 博客园  发布时间: 2010-10-01 00:42  阅读: 1618 次  推荐: 0                  原文链接  [收藏] Lesson ...

  4. C++Primer第五版——习题答案详解(九)

    习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第10章 泛型算法 练习10.1 #include<iostream> #i ...

  5. 关于想通过ros的dstnat实现公网IP nat 公网IP的情况

    转发群里大神的“苏州-海豚在跳舞”的图 理论上客户机收到2.2.2.2过来的包应该直接丢弃.因为它并没有给2.2.2.2发过包.这里不知道如果在2.2.2.2上做 src-nat伪装成1.1.1.1回 ...

  6. [UE4]Border

    Border: 边界; 边; 镶边; 包边; Border也是一个容器,只能包含一个子元素. 一.添加一个名为testBorder的UserWidget,添加一个Border到默认成Canvas Pa ...

  7. CentOS安装mysql源码包

    1.# cd /usr/local/src 2.上传mysql.tar.gz文件 3.# tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz 4.# ...

  8. (整理)在REHL6.5上部署ASP.NET MVC

    最近项目要使用Linux服务器(REHL6.5)+MySQL,因此特尝试操作. 1 Linux 安装Jexus 1.1 下载Jexus 因为服务器没有安装Xwindows,Jexus的下载又出现问题, ...

  9. Chapter 5 数组:为什么很多编程语言种数组都是从0开始编号?

    如何实现随机访问? 线性表:数组,队列,链表,栈 非线性表:树,图 总结:数组用一块连续的内存空间,来存储相同类型的一组数据,最大的特点就是支持随机访问,但插入,删除操作也因此变得比较低效,平均情况时 ...

  10. 笔记本 原来win10系统改装win7系统遇到 invaid signature detected.check secure boot policy setup问题

    这次操作的笔记本电脑是   华硕R414U 大家如果遇到类似问题的话也可以参考这个方法,但是必须搞清楚电脑的型号,型号不同操作起来有差别的 我这里选择的重装系统的方法是最简单粗暴的硬盘安装方法,怎么硬 ...