Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it necessary to call AudioSession.setActive(true) ? #43

Open
JDChi opened this issue Oct 8, 2021 · 5 comments
Open

Is it necessary to call AudioSession.setActive(true) ? #43

JDChi opened this issue Oct 8, 2021 · 5 comments

Comments

@JDChi
Copy link

JDChi commented Oct 8, 2021

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()

@ryanheise
Copy link
Owner

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.

@JDChi
Copy link
Author

JDChi commented Oct 8, 2021

@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 .

@ryanheise
Copy link
Owner

I've already implemented those.

@JDChi
Copy link
Author

JDChi commented Oct 8, 2021

I've already implemented those.

Well, do you want to wrap them to AudioSession in the future ?

@ryanheise
Copy link
Owner

ryanheise commented Oct 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants