[
https://issues.apache.org/jira/browse/CB-11966?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15554968#comment-15554968
]
Jörn Zaefferer commented on CB-11966:
-------------------------------------
I managed to fix my specific problem with a fork that always sets
AUDIOFOCUS_GAIN_TRANSIENT. It also abandons audio focus when all players are
released:
https://github.com/ilovept/cordova-plugin-media/commit/7e77477ff98be206780f03b3a82f1ee12c9db4e9
Since I have no idea how to expose the durationHint, there's little point in
sending a pull request for this commit. With some guidance on the API design, I
might be able to put something together. Otherwise I hope my commit can be a
starting point for whoever ends up having to solve the same issue.
> Make durationHint parameter for requestAudioContext configurable
> ----------------------------------------------------------------
>
> Key: CB-11966
> URL: https://issues.apache.org/jira/browse/CB-11966
> Project: Apache Cordova
> Issue Type: New Feature
> Components: Plugin Media
> Reporter: Jörn Zaefferer
> Labels: android
>
> Android supports playback of so-called transient audio, like instructions
> from navigation software or a beep from a timer or messenger, via the
> AudioManager#requestAudioFocus method's `durationHint` parameter. Currently
> this is hardcoded to AUDIOFOCUS_GAIN:
> https://github.com/apache/cordova-plugin-media/blob/0a5a72df42ddd91c50f2a36d0c58408c3b43a9fd/src/android/AudioHandler.java#L445
> That causes all other audio, like music or a podcast, to be stopped. Setting
> it instead to AUDIOFOCUS_GAIN_TRANSIENT would only pause other audio while
> the sound is playing. AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK allows other audio
> to only lower volume, without pausing. There's also
> AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE, but I don't understand what that does.
> For more background, see
> https://developer.android.com/training/managing-audio/audio-focus.html
> I suggest adding a (Android specific) option to override the default to one
> of the transient values.
> Since the caller is itself called by `startPlayingAudio()` (
> https://github.com/apache/cordova-plugin-media/blob/0a5a72df42ddd91c50f2a36d0c58408c3b43a9fd/src/android/AudioHandler.java#L318
> ), it might make sense to make this a parameter of the `media.play()`
> method. I'm not sure what a good format would be. Passing an `int` is kinda
> bad. Apparently none of the existing methods have any configuration.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]