diff --git a/android/src/main/java/com/brentvatne/exoplayer/DefaultReactExoplayerConfig.java b/android/src/main/java/com/brentvatne/exoplayer/DefaultReactExoplayerConfig.java deleted file mode 100644 index 2a9b640e..00000000 --- a/android/src/main/java/com/brentvatne/exoplayer/DefaultReactExoplayerConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.brentvatne.exoplayer; - -import android.content.Context; - -import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter; -import androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy; -import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy; - -public class DefaultReactExoplayerConfig implements ReactExoplayerConfig { - - private final DefaultBandwidthMeter bandwidthMeter; - private boolean disableDisconnectError = false; - - public DefaultReactExoplayerConfig(Context context) { - this.bandwidthMeter = new DefaultBandwidthMeter.Builder(context).build(); - } - - public LoadErrorHandlingPolicy buildLoadErrorHandlingPolicy(int minLoadRetryCount) { - if (this.disableDisconnectError) { - // Use custom error handling policy to prevent throwing an error when losing network connection - return new ReactExoplayerLoadErrorHandlingPolicy(minLoadRetryCount); - } - return new DefaultLoadErrorHandlingPolicy(minLoadRetryCount); - } - - public void setDisableDisconnectError(boolean disableDisconnectError) { - this.disableDisconnectError = disableDisconnectError; - } - - public boolean getDisableDisconnectError() { - return this.disableDisconnectError; - } - - @Override - public DefaultBandwidthMeter getBandwidthMeter() { - return bandwidthMeter; - } -} diff --git a/android/src/main/java/com/brentvatne/exoplayer/DefaultReactExoplayerConfig.kt b/android/src/main/java/com/brentvatne/exoplayer/DefaultReactExoplayerConfig.kt new file mode 100644 index 00000000..ce5d3bfd --- /dev/null +++ b/android/src/main/java/com/brentvatne/exoplayer/DefaultReactExoplayerConfig.kt @@ -0,0 +1,26 @@ +package com.brentvatne.exoplayer + +import android.content.Context +import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter +import androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy +import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy + +class DefaultReactExoplayerConfig(context: Context) : ReactExoplayerConfig { + + private var bandWidthMeter: DefaultBandwidthMeter = DefaultBandwidthMeter.Builder(context).build() + private var disableDisconnectError: Boolean = false + override fun buildLoadErrorHandlingPolicy(minLoadRetryCount: Int): LoadErrorHandlingPolicy = + if (disableDisconnectError) { + ReactExoplayerLoadErrorHandlingPolicy(minLoadRetryCount) + } else { + DefaultLoadErrorHandlingPolicy(minLoadRetryCount) + } + + override fun setDisableDisconnectError(disableDisconnectError: Boolean) { + this.disableDisconnectError = disableDisconnectError + } + + override fun getDisableDisconnectError(): Boolean = disableDisconnectError + + override fun getBandwidthMeter(): DefaultBandwidthMeter = bandWidthMeter +}