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

setting to disable AudioFocus request #295

Closed
honzasvasek opened this issue Feb 2, 2021 · 10 comments
Closed

setting to disable AudioFocus request #295

honzasvasek opened this issue Feb 2, 2021 · 10 comments
Assignees
Labels
3 testing enhancement New feature or request

Comments

@honzasvasek
Copy link

Is your feature request related to a problem? Please describe.

I am changing my app from using the audioplayers plugin to the just_audio plugin but just_audio is requesting Audio Focus and for my app I specifically do not want to request Audio Focus.

I want my app to be able to run in parallel with music streaming apps like Spotify, without the stream ducking or stopping.

Right now I am developing on Android only, but will use iOS in a later stage

Describe the solution you'd like

I'd like a setting to disable the Audio Focus request

Describe alternatives you've considered

Maybe this should be an option in the audio_session plugin

@ryanheise
Copy link
Owner

I'm not sure about adding it to the audio_session plugin, but I do like the idea of adding another option to the AudioPlayer constructor, in addition to the current handleInterruptions.

Note that now that the plugin has been migrated to null-safety, it is likely that this feature will be added to the nnbd branch.

@ryanheise
Copy link
Owner

This is now implemented in the latest commit on the nnbd branch. You can now pass handleAudioSessionActivation: true as a constructor parameter to prevent just_audio from handling activation itself.

Let me know if you find the API suitable or if you would like further changes.

Note that to try it out, you'll need to use a git dependency with a ref pointing to the nnbd branch and also a path pointing to the just_audio subdirectory of the repository (documented here).

@honzasvasek
Copy link
Author

honzasvasek commented Feb 2, 2021 via email

@ryanheise
Copy link
Owner

Great to hear! I'll close this issue. Note that I may make further commits for other features before the next release, so it may be safer if you are directly depending on the git version to reference that specific commit in the ref. That way if I break anything in a subsequent commit, it won't affect your app.

@tim-tonic
Copy link

tim-tonic commented Mar 23, 2021

First of all I wan't to thank you for your amazing work.
I assume that this feature is included in the current version 0.7.2 (pub.dev). Is that right?
Because my Spotify playback is interrupted as soon as the AudioPlayer starts playing.

Did I miss something? Here is my code..

player = AudioPlayer(handleAudioSessionActivation: true);
await player.setAsset('assets/mp3/test.mp3', preload: true).then((value) {
player.play();
});

Thank you in advance.

@ryanheise
Copy link
Owner

In terms of other audio apps interrupting your audio app, AVQueuePlayer (the underlying iOS API) has a mind of its own when it comes to pausing audio during an interruption. There is no way I can control it from within just_audio. That is one of the reasons #334 may be a good idea.

But in terms of your audio app interrupting Spotify, that happens because you have requested just_audio to handle the audio session activation. Try passing in a false value, OR to create a better behaved app, try configuring the audio session with parameters that allow mixing with other audio apps.

@tim-tonic
Copy link

Thx for your feedback. My app should behave like a navigation app. Therefore, the current playback (spotify) should not be paused. My audio should behave like a push notification sound. Is this possible with your libs?

@ryanheise
Copy link
Owner

You should look into audio_session which exposes all of the iOS audio session settings. The documentation for these settings is the source Apple documentation.

@tim-tonic
Copy link

Thank you.

@github-actions
Copy link

github-actions bot commented Nov 4, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 testing enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants