Audio Session Management

Implement audio ducking for the StreamLayer Android SDK. Use SLRAppHost.Delegate to lower stream volume during Watch Party calls, social content playback, and gamification features.

Audio Management

Audio Ducking

Certain units within the StreamLayer Element may require a decrease in the main video's audio level. For example, when a user is in a Watch Party call, the SDK needs the device's microphone and speaker. The SDK requests the host app to lower the stream volume, ensuring high call quality and a good experience. Audio ducking is also needed during social content and gamification video playback.

Implementing Audio Ducking

The StreamLayer SDK provides an interface with callback functions to notify when audio ducking is required. Implement SLRAppHost.Delegate, then register your implementation using SLRAppHost.delegate.

Here is sample code using SLRAppHost.Delegate in the Activity class:

import io.streamlayer.sdk.StreamLayer

// app host player
private val appHostDelegate = object : SLRAppHost.Delegate {

   override fun requestAudioDucking(level: Float) {
        exoHelper.notifyDuckingChanged(true, level)
   }

   override fun disableAudioDucking() {
        exoHelper.notifyDuckingChanged(false)
   }

   override fun setAudioVolume(value: Float) {
        exoHelper.player.volume = value
   }

   override fun getAudioVolumeListener(): Flow<Float> = exoHelper.getAudioVolumeListener()

   //other functions

}


override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     // add delegate
     withStreamLayerUI { delegate = appHostDelegate }
}


override fun onDestroy() {
     // remove delegate
     withStreamLayerUI { delegate = null }
     super.onDestroy()
}

For a complete implementation example with ExoPlayer, see the demo app.


Related