Audio Session Management

Audio Management

Audio Ducking

To ensure the best user experience, certain overlays may require a decrease in the main video's audio level. For instance, when the user is making use of the Watch Party feature, the feature needs to use the device's microphone and speaker. The SDK will request the host app lower the volume of the current stream, to ensure a high call quality and good experience during the call. Audio ducking is also needed for the Twitter and Gamification features during video playback.

Implement the Audio Ducking

The StreamLayer class provides an interface with a callback function to notify when audio ducking is required. This will require you to implement SLRAppHost.Delegate. After that you can add or remove your implementation using SLRAppHost.delegate property.

Here is sample code that illustrates solution of 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()
}

Examples of implementation SLRAppHost.Deleagte with ExoPlayer can be found here