AudiosessionSetActive
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);
苹果官方有写:
————————————————————————————————————————————————————————————————————————————
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
On This Page
Declaration
- (BOOL)setActive:(BOOL)active
withOptions:(AVAudioSessionSetActiveOptions)options
error:(NSError * _Nullable *)outError;
Parameters
active-
Specify
YESto activate your app’s audio session, orNOto deactivate it. options-
An integer bit mask containing one or more constants from the
AVAudioSessionSetActiveOptionsenumeration. 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 innil.
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的更多相关文章
- 一篇对iOS音频比较完善的文章
转自:http://www.cnblogs.com/iOS-mt/p/4268532.html 感谢作者:梦想通 前言 从事音乐相关的app开发也已经有一段时日了,在这过程中app的播放器几经修改我也 ...
- [ios]app后台运行
参考:http://www.douban.com/note/375127736/ 1 使用开源代码MMPDeepSleepPreventer将文件加入工程,包括音频文件.可以在源文件中加入单例,便于使 ...
- iOS编程修改系统音量
iOS的AVFoundation框架提供了基本的音视频播放工具,我们基本上可以靠其中提供的类完成绝大部分的音视频播放任务.但是在音频播放的输出音量的处理上,苹果的策略比较保守.尽管AVPlayer和A ...
- iOS调节系统音量
目录[-] 使用MPVolumeView 编程实现系统音量调节2 通过MPVolumeSlider的实例来操作系统音量 有问题!我不喜欢系统弹出音量提示 还有问题,我修改了系统音量但是不是通过我的UI ...
- IOS 音频播放
iOS音频播放 (一):概述 前言 从事音乐相关的app开发也已经有一段时日了,在这过程中app的播放器几经修改我也因此对于iOS下的音频播放实现有了一定的研究.写这个系列的博客目的一方面希望能够抛砖 ...
- iOS音频播放(二):AudioSession
(本文转自码农人生) 前言 在实施前一篇中所述的7个步骤步之前还必须面对一个麻烦的问题,AudioSession. AudioSession简介 AudioSession这个玩意的主要功能包括以下 ...
- iOS 监听声音按键
有时在项目中需要监听用户是否按下了物理声音键,然后来做某些操作,如:你自定义了一个照相功能,希望用户按下声音按键时也能进行拍照,苹果自带的照相机就有这种功能. 监听物理声音键是否按下的方法有很多中,我 ...
- DOUAudioStreamer 中kqueue的应用
DOUAudioStreamer是一个基于Core Audio的流式音频播放器,其中的DOUAudioEventLoop通过kqueue来控制音频的各种状态. kqueue简介(详情请看官方manua ...
- iOS录音后播放声音小,AudioSessionInitialize failed,AudioQueueStart failed (-50)
方法1: UInt32 audioRoute = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty(kAudioSess ...
随机推荐
- crontab 相关
修改编辑器 select-editor 查看服务状态 service cron status (linux下为crond ,ubuntu为cron) 1-59/2 1,10,12 * * * ...
- PythonStudy——字典的定义 Dictionary definition
# 空字典 d1 = {} d2 = dict() # 用map映射创建字典 d3 = dict({'a': 1, 'b': 1}) print(d3) # 用关键字赋值方式 d4 = dict(na ...
- LOJ 2991 「THUSC 2016」补退选——trie+线段树合并或vector
题目:https://loj.ac/problem/2291 想了线段树合并的做法.就是用线段树维护 trie 的每个点在各种时间的操作. 然后线段树合并一番,线段树维护前缀最大值,就是维护最大子段和 ...
- 配置jboss为windows服务
先确保jdk和jboss的环境变量是正常可用的 1.(下载binaries 2.x.x-windows x86)找到service.bat和jbosssvc.exe两个文件 1.1 binaries ...
- write(6)、write(10)和write(16)以及read(6)、read(10)和read(16)的区别与应用
大家知道,我们读写硬盘的时候发送的命令为SCSI READ或SCSI WRITE.即SCSI读和SCSI写命令.但是READ和WRITE有很多种,这些命令的应用场合是什么呢? 最重要的一点就是,这是跟 ...
- 深入理解Spring Boot属性配置文件
我们在开发Spring Boot应用时,通常同一套程序会被应用和安装到几个不同的环境,比如:开发.测试.生产等.其中每个环境的数据库地址.服务器端口等等配置都会不同,如果在为不同环境打包时都要频繁修改 ...
- Windows不要使用记事本编辑文本文件
摘自:廖雪峰 千万不要使用Windows自带的记事本编辑任何文本文件.原因是Microsoft开发记事本的团队使用了一个非常弱智的行为来保存UTF-8编码的文件,他们自作聪明地在每个文件开头添加了0x ...
- 如何从 VSS 迁移到Team Foundation Server
TFS 2012自带了vss upgrade wizard工具, 在Team Foundation Server管理控制台左侧的最后一个菜单其他工具和组件中,选择Visual SourceSafe升级 ...
- 报错:Exception in thread "main" com.typesafe.config.ConfigException$UnresolvedSubstitution
报错现象: 报错原因: pom文件中的jar包太高,可以降低jar包的版本号. 报错解决: 我将2.11换成了2.10,即可解决. <dependency> <groupId> ...
- Pascal语言(存档)
数据类型 标准函数 运算符和表达式 输入语句 输出语句 if语句 case语句 for语句 while语句 repeat语句 函数与过程 形参与实参 全局变量与局部变量 数组 字符串 枚举 子界 集合 ...