how to find out if audio session is active in iOS
Asked Answered
S

3

21

I'm using AudioSessionSetActive(true) and AudioSessionSetActive(false) for setting the AudioSession to true or false in my iOS app. At any point, I want to find out whether the session is active or not. Is there a way to do that?

Snitch answered 4/10, 2011 at 8:34 Comment(0)
R
9

Just ran into the same thing! There is no AudioSessionProperty key for querying whether or not the session is active. I believe this is another one of those set it and forget it deals where Apple believes apps should behave a certain way. Eg. most apps shouldn't need to know the state they should just set it as they need audio and kill it unconditionally as they are done playing audio. Of course this only works for the 90%. Apologies as this is not the best answer, I'm only reporting my suspicions. Maybe others have a better idea?

Rubicon answered 19/10, 2011 at 21:36 Comment(0)
S
5

You can check if any audio is playing as it was launched by another app by inspecting the otherAudioPlaying property when you launch the app. For internal tracking perhaps you could use a boolean when you do the AudioSessionSetActive(BOOL setActive) call. Though use of BOOL does not sound as a wonderful approach. Given my current knowledge I couldnt find any other way of determining if the AudioSession is active or not.

Spindly answered 23/2, 2015 at 7:42 Comment(0)
H
4

You can use this api to find out if audio session is active in iOS.

BOOL isPlaying = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
Heartworm answered 8/9, 2018 at 1:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.