Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-11966

Make durationHint parameter for requestAudioContext configurable

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cordova-plugin-media
    • Labels:

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jzaefferer Jörn Zaefferer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: