audio_session
audio_session copied to clipboard
Is it necessary to call AudioSession.setActive(true) ?
In my app, I only want to detect whether another app is playing audio , so that I can toast something .
But if I only use AudioSession.interruptionEventStream.listen
, if another app start to play music , I can't receive any event. However, if I call AudioSession.setActive(true)
, I will receive the interruption event. But that means it will stop the another app's playing audio .
It seems that I need a API like AudioSession.isOtherAudioPlaying()
。
Hi @JDNew , setActive
wraps AVAudioSession.setActive
on Apple, and AudioManager.requestAudioFocus
on Android. They ultimately do the same thing which is to handle interruptions to your own audio session. If you haven't activated an audio session for your app, you won't get any interruption.
As for other capabilities, audio_session just wraps Apple's AVAudioSession API and Android's AudioManager API, so I would suggest consulting the source documentation from Apple and Google to see what is actually possible on each platform. If you find a method in one of those two native APIs that will help you and you find that I haven't exposed it yet in this plugin, let me know and I'll add it.
@ryanheise Thanks for you reply .
Please look at this : Detect background audio playing on Android.
On the audio_session project , I found that you have isOtherAudioPlaying
in ios . And I think maybe you can add AudioManager. IsMusicActive
on Android. So that we can have the API to check whether is another app is playing audio directly .
I've already implemented those.
I've already implemented those.
Well, do you want to wrap them to AudioSession
in the future ?
Yes it's a good idea to add more cross-platform convenience methods to AudioSession
over time. Let me know how the individual platform methods work since they're untested. If they work for you, I can make a wrapper in AudioSession
.