feat(android): make buffering strategy dynamic (#3756)

* chore: rework bufferConfig to make it more generic and reduce ReactExoplayerView code size
* feat: expose bufferingStrategy to app and change default behavior
rename disableBuffering undocumented prop to bufferingStrategy and document it.
before this change, default was 'dependingOnMemory'. It can trigger some unnecessary gc() call on android.
This commit is contained in:
Olivier Bouillet
2024-05-11 22:02:04 +02:00
committed by GitHub
parent 1a48f190f0
commit e420418e8f
7 changed files with 105 additions and 31 deletions

View File

@@ -0,0 +1,47 @@
package com.brentvatne.common.api
import com.brentvatne.common.toolbox.DebugLog
/**
* Define how exoplayer with load data and parsing helper
*/
class BufferingStrategy {
/**
* Define how exoplayer with load data
*/
enum class BufferingStrategyEnum {
/**
* default exoplayer strategy
*/
Default,
/**
* never load more than needed
*/
DisableBuffering,
/**
* use default strategy but pause loading when available memory is low
*/
DependingOnMemory
}
companion object {
private const val TAG = "BufferingStrategy"
/**
* companion function to transform input string to enum
*/
fun parse(src: String?): BufferingStrategyEnum {
if (src == null) return BufferingStrategyEnum.Default
return try {
BufferingStrategyEnum.valueOf(src)
} catch (e: Exception) {
DebugLog.e(TAG, "cannot parse buffering strategy " + src)
BufferingStrategyEnum.Default
}
}
}
}