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

Fix android audio focus management #1

Closed
wants to merge 1 commit into from
Closed

Fix android audio focus management #1

wants to merge 1 commit into from

Conversation

danieldspx
Copy link

Everytime we instantiate TNSPlayer() it was requesting the audio focus and not abandoning it (until we call dispose() which is not always what we want). This is not recommended according to Android documentation and introduces a bug since this is not the expected behaviour.
Those issues are facing exactly this bug: nstudio#142 nstudio#137

Android docs states that a well-behaved audio app should manage audio focus according to these general guidelines:

Call requestAudioFocus() immediately before starting to play and verify that the call returns AUDIOFOCUS_REQUEST_GRANTED. If you design your app as we describe in this guide, the call to requestAudioFocus() should be made in the onPlay() callback of your media session.

When another app gains audio focus, stop or pause playing, or duck the volume down.

When playback stops, abandon audio focus.

Therefore this pull request strictly obeys Android docs and fix the problem. It does not break existing code, only introduces the expected behaviour. So anyone can update the package and get the expected behaviour. I have also introduced the possibility to pass the durationHint (default is still AUDIOFOCUS_GAIN) to TNSPlayer constructor so we can determine differents behaviors by the system and the other application that previously held audio focus. Refer to the updated README.md .
Note: This update is only for android player.

@danieldspx
Copy link
Author

I am closing this PR because I think I should make it to nstudio/nativescript-audio

@danieldspx danieldspx closed this May 31, 2020
@danieldspx danieldspx changed the title Fix audio focus management Fix android audio focus management May 31, 2020
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

Successfully merging this pull request may close these issues.

1 participant