zoukankan      html  css  js  c++  java
  • 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);


    苹果官方有写:
    ————————————————————————————————————————————————————————————————————————————
    Instance Method

    setActive:withOptions:error:

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

    • iOS 6.0+
    • tvOS 9.0+
    • watchOS 2.0+
    • 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.



  • 相关阅读:
    华为部分真机调试无法显示log问题解决
    Android Studio 配置模拟器AVD存放路径(默认在c盘,解决c盘空间不够问题)
    Android Studio Build APK没有报错,但是Generate signed apk报错
    安卓如何将TXT文件写到特定路径
    unity 显示、隐藏Android导航栏
    Unity 代码集锦之图片处理
    打开文件夹
    MVC总结
    unity 获取UGUI中的Text字的坐标
    Unity WWW类调用http
  • 原文地址:https://www.cnblogs.com/8335IT/p/9925589.html
Copyright © 2011-2022 走看看