Steps to reproduce
- Enable the
Dynamic Range Compressor setting in CloudStream Player Settings.
- Play any video in the player and turn ON the compressor in the compressor dialog (or apply a preset).
- Close the player or play another episode/video.
- Listen to the audio during playback: the compressor is NOT active (dialogues are quiet, volume spikes are untamed).
- Tap the screen to reveal player controls and tap the Compressor button (
playerCompressorBtt) to open the compressor dialog.
- The exact instant the dialog opens, the compressor immediately kicks in and the audio becomes compressed / boosted.
Expected behavior
When DynamicRangeCompressor has been enabled by the user, newly played videos should automatically restore and activate the compressor settings upon playback initialization without requiring the user to tap the screen and open the compressor dialog manually.
Actual behavior
Every newly started video plays with DynamicRangeCompressor.enabled = false. It is only switched to enabled = true when the user manually taps the compressor button to open showCompressorDialog().
Cloudstream version and commit hash
Pre-release / master branch (Commit 4e2516d / PR #3117)
Android version
Android 12+ (All versions, TV and Phone)
Logcat
N/A (Functional lifecycle timing issue in player initialization)
Other details
Root Cause Analysis
In app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt:
restoreCompressorSettings() is only called in two locations:
- In
onBindingCreated():
playerBinding?.apply {
playerSpeedBtt.isVisible = playBackSpeedEnabled
playerCompressorBtt.isVisible = playBackCompressorEnabled
if (playBackCompressorEnabled) {
restoreCompressorSettings()
}
...
- In
showCompressorDialog():
private fun showCompressorDialog() {
val act = activity ?: return
val compressor = (player as? CS3IPlayer)?.compressor ?: return
// Always restore — CS3IPlayer is recreated between videos
restoreCompressorSettings()
...
Inside restoreCompressorSettings():
protected fun restoreCompressorSettings() {
val c = (player as? CS3IPlayer)?.compressor ?: return
c.enabled = getKey(COMPRESSOR_ENABLED_KEY) ?: false
c.threshold = getKey(COMPRESSOR_THRESHOLD_KEY) ?: -24f
c.ratio = getKey(COMPRESSOR_RATIO_KEY) ?: 8f
c.attackMs = getKey(COMPRESSOR_ATTACK_KEY) ?: 5f
c.releaseMs = getKey(COMPRESSOR_RELEASE_KEY) ?: 400f
c.makeupGain = getKey(COMPRESSOR_MAKEUP_KEY) ?: 12f
}
The Bug:
When onBindingCreated() runs, the media stream has not yet started loading and ExoPlayer has not yet built its renderers. Therefore, (player as? CS3IPlayer)?.compressor is still null.
As a result, val c = (player as? CS3IPlayer)?.compressor ?: return immediately returns without doing anything.
Later, when CS3IPlayer.load() executes and builds ExoPlayer, a new instance of DynamicRangeCompressor is created. In DynamicRangeCompressor.kt:
@Volatile var enabled: Boolean = false
The compressor is initialized with enabled = false. Because restoreCompressorSettings() is never called again after load(), the compressor remains OFF throughout playback.
When the user manually taps the compressor button while the video is playing, showCompressorDialog() is invoked. At that point, compressor is no longer null, so restoreCompressorSettings() finally runs and turns c.enabled = true.
Suggested Fix
Call restoreCompressorSettings() once the player / renderers are actually initialized (e.g. inside CS3IPlayer.load() after creating DynamicRangeCompressor, or on Player.Listener.onPlaybackStateChanged / onRenderedFirstFrame in FullScreenPlayer).
Alternatively, pass the initial enabled state and saved values from DataStore directly into DynamicRangeCompressor's constructor or factory when CS3IPlayer creates it in setRenderersFactory.
Acknowledgements
Steps to reproduce
Dynamic Range Compressorsetting in CloudStream Player Settings.playerCompressorBtt) to open the compressor dialog.Expected behavior
When
DynamicRangeCompressorhas been enabled by the user, newly played videos should automatically restore and activate the compressor settings upon playback initialization without requiring the user to tap the screen and open the compressor dialog manually.Actual behavior
Every newly started video plays with
DynamicRangeCompressor.enabled = false. It is only switched toenabled = truewhen the user manually taps the compressor button to openshowCompressorDialog().Cloudstream version and commit hash
Pre-release / master branch (Commit 4e2516d / PR #3117)
Android version
Android 12+ (All versions, TV and Phone)
Logcat
Other details
Root Cause Analysis
In
app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt:restoreCompressorSettings()is only called in two locations:onBindingCreated():showCompressorDialog():Inside
restoreCompressorSettings():The Bug:
When
onBindingCreated()runs, the media stream has not yet started loading and ExoPlayer has not yet built its renderers. Therefore,(player as? CS3IPlayer)?.compressoris stillnull.As a result,
val c = (player as? CS3IPlayer)?.compressor ?: returnimmediately returns without doing anything.Later, when
CS3IPlayer.load()executes and builds ExoPlayer, a new instance ofDynamicRangeCompressoris created. InDynamicRangeCompressor.kt:The compressor is initialized with
enabled = false. BecauserestoreCompressorSettings()is never called again afterload(), the compressor remains OFF throughout playback.When the user manually taps the compressor button while the video is playing,
showCompressorDialog()is invoked. At that point,compressoris no longer null, sorestoreCompressorSettings()finally runs and turnsc.enabled = true.Suggested Fix
Call
restoreCompressorSettings()once the player / renderers are actually initialized (e.g. insideCS3IPlayer.load()after creatingDynamicRangeCompressor, or onPlayer.Listener.onPlaybackStateChanged/onRenderedFirstFrameinFullScreenPlayer).Alternatively, pass the initial enabled state and saved values from
DataStoredirectly intoDynamicRangeCompressor's constructor or factory whenCS3IPlayercreates it insetRenderersFactory.Acknowledgements