Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find out if audio session is active in iOS

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?

like image 748
Namratha Avatar asked Oct 04 '11 08:10

Namratha


2 Answers

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?

like image 120
Cliff Avatar answered Oct 17 '22 21:10

Cliff


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.

like image 24
Sumeet Avatar answered Oct 17 '22 22:10

Sumeet