chore: move minLoadRetryCount into source property (#4233)

This commit is contained in:
Olivier Bouillet 2024-10-16 23:41:22 +02:00 committed by GitHub
parent a8d5841c7c
commit f04b233a40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 17 deletions

View File

@ -48,6 +48,9 @@ class Source {
/** Metadata to display in notification */ /** Metadata to display in notification */
var metadata: Metadata? = null var metadata: Metadata? = null
/** Allowed reload before failure notification */
var minLoadRetryCount = 3
/** http header list */ /** http header list */
val headers: MutableMap<String, String> = HashMap() val headers: MutableMap<String, String> = HashMap()
@ -91,7 +94,8 @@ class Source {
contentStartTime == other.contentStartTime && contentStartTime == other.contentStartTime &&
cmcdProps == other.cmcdProps && cmcdProps == other.cmcdProps &&
sideLoadedTextTracks == other.sideLoadedTextTracks && sideLoadedTextTracks == other.sideLoadedTextTracks &&
adsProps == other.adsProps adsProps == other.adsProps &&
minLoadRetryCount == other.minLoadRetryCount
) )
} }
@ -159,6 +163,7 @@ class Source {
private const val PROP_SRC_ADS = "ad" private const val PROP_SRC_ADS = "ad"
private const val PROP_SRC_TEXT_TRACKS_ALLOW_CHUNKLESS_PREPARATION = "textTracksAllowChunklessPreparation" private const val PROP_SRC_TEXT_TRACKS_ALLOW_CHUNKLESS_PREPARATION = "textTracksAllowChunklessPreparation"
private const val PROP_SRC_TEXT_TRACKS = "textTracks" private const val PROP_SRC_TEXT_TRACKS = "textTracks"
private const val PROP_SRC_MIN_LOAD_RETRY_COUNT = "minLoadRetryCount"
@SuppressLint("DiscouragedApi") @SuppressLint("DiscouragedApi")
private fun getUriFromAssetId(context: Context, uriString: String): Uri? { private fun getUriFromAssetId(context: Context, uriString: String): Uri? {
@ -223,7 +228,7 @@ class Source {
} }
source.textTracksAllowChunklessPreparation = safeGetBool(src, PROP_SRC_TEXT_TRACKS_ALLOW_CHUNKLESS_PREPARATION, true) source.textTracksAllowChunklessPreparation = safeGetBool(src, PROP_SRC_TEXT_TRACKS_ALLOW_CHUNKLESS_PREPARATION, true)
source.sideLoadedTextTracks = SideLoadedTextTrackList.parse(safeGetArray(src, PROP_SRC_TEXT_TRACKS)) source.sideLoadedTextTracks = SideLoadedTextTrackList.parse(safeGetArray(src, PROP_SRC_TEXT_TRACKS))
source.minLoadRetryCount = safeGetInt(src, PROP_SRC_MIN_LOAD_RETRY_COUNT, 3)
val propSrcHeadersArray = safeGetArray(src, PROP_SRC_HEADERS) val propSrcHeadersArray = safeGetArray(src, PROP_SRC_HEADERS)
if (propSrcHeadersArray != null) { if (propSrcHeadersArray != null) {
if (propSrcHeadersArray.size() > 0) { if (propSrcHeadersArray.size() > 0) {

View File

@ -207,7 +207,6 @@ public class ReactExoplayerView extends FrameLayout implements
private float rate = 1f; private float rate = 1f;
private AudioOutput audioOutput = AudioOutput.SPEAKER; private AudioOutput audioOutput = AudioOutput.SPEAKER;
private float audioVolume = 1f; private float audioVolume = 1f;
private int minLoadRetryCount = 3;
private BufferConfig bufferConfig = new BufferConfig(); private BufferConfig bufferConfig = new BufferConfig();
private int maxBitRate = 0; private int maxBitRate = 0;
private boolean hasDrmFailed = false; private boolean hasDrmFailed = false;
@ -1209,7 +1208,7 @@ public class ReactExoplayerView extends FrameLayout implements
MediaSource mediaSource = mediaSourceFactory MediaSource mediaSource = mediaSourceFactory
.setDrmSessionManagerProvider(drmProvider) .setDrmSessionManagerProvider(drmProvider)
.setLoadErrorHandlingPolicy( .setLoadErrorHandlingPolicy(
config.buildLoadErrorHandlingPolicy(minLoadRetryCount) config.buildLoadErrorHandlingPolicy(source.getMinLoadRetryCount())
) )
.createMediaSource(mediaItem); .createMediaSource(mediaItem);
@ -2276,12 +2275,6 @@ public class ReactExoplayerView extends FrameLayout implements
} }
} }
public void setMinLoadRetryCountModifier(int newMinLoadRetryCount) {
minLoadRetryCount = newMinLoadRetryCount;
releasePlayer();
initializePlayer();
}
public void setPlayInBackground(boolean playInBackground) { public void setPlayInBackground(boolean playInBackground) {
this.playInBackground = playInBackground; this.playInBackground = playInBackground;
} }

View File

@ -42,7 +42,6 @@ class ReactExoplayerViewManager(private val config: ReactExoplayerConfig) : View
private const val PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval" private const val PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval"
private const val PROP_REPORT_BANDWIDTH = "reportBandwidth" private const val PROP_REPORT_BANDWIDTH = "reportBandwidth"
private const val PROP_RATE = "rate" private const val PROP_RATE = "rate"
private const val PROP_MIN_LOAD_RETRY_COUNT = "minLoadRetryCount"
private const val PROP_MAXIMUM_BIT_RATE = "maxBitRate" private const val PROP_MAXIMUM_BIT_RATE = "maxBitRate"
private const val PROP_PLAY_IN_BACKGROUND = "playInBackground" private const val PROP_PLAY_IN_BACKGROUND = "playInBackground"
private const val PROP_DISABLE_FOCUS = "disableFocus" private const val PROP_DISABLE_FOCUS = "disableFocus"
@ -187,11 +186,6 @@ class ReactExoplayerViewManager(private val config: ReactExoplayerConfig) : View
videoView.setMaxBitRateModifier(maxBitRate.toInt()) videoView.setMaxBitRateModifier(maxBitRate.toInt())
} }
@ReactProp(name = PROP_MIN_LOAD_RETRY_COUNT)
fun setMinLoadRetryCount(videoView: ReactExoplayerView, minLoadRetryCount: Int) {
videoView.setMinLoadRetryCountModifier(minLoadRetryCount)
}
@ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false) @ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false)
fun setPlayInBackground(videoView: ReactExoplayerView, playInBackground: Boolean) { fun setPlayInBackground(videoView: ReactExoplayerView, playInBackground: Boolean) {
videoView.setPlayInBackground(playInBackground) videoView.setPlayInBackground(playInBackground)

View File

@ -379,6 +379,8 @@ maxBitRate={2000000} // 2 megabits
``` ```
### `minLoadRetryCount` ### `minLoadRetryCount`
> [!WARNING]
> deprecated, use `source.minLoadRetryCount` key instead
<PlatformsList types={['Android']} /> <PlatformsList types={['Android']} />
@ -903,6 +905,23 @@ source={{
}} }}
``` ```
#### `minLoadRetryCount`
<PlatformsList types={['Android']} />
Sets the minimum number of times to retry loading data before failing and reporting an error to the application. Useful to recover from transient internet failures.
Default: 3. Retry 3 times.
Example:
```javascript
source={{
uri: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
minLoadRetryCount={5} // retry 5 times
}}
```
#### `textTracks` #### `textTracks`
<PlatformsList types={['Android', 'iOS', 'visionOS']} /> <PlatformsList types={['Android', 'iOS', 'visionOS']} />

View File

@ -124,6 +124,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onVideoTracks, onVideoTracks,
onAspectRatio, onAspectRatio,
localSourceEncryptionKeyScheme, localSourceEncryptionKeyScheme,
minLoadRetryCount,
...rest ...rest
}, },
ref, ref,
@ -233,6 +234,8 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
? {adTagUrl: adTagUrl, adLanguage: adLanguage} ? {adTagUrl: adTagUrl, adLanguage: adLanguage}
: undefined); : undefined);
const _minLoadRetryCount =
_source.minLoadRetryCount || minLoadRetryCount;
return { return {
uri, uri,
isNetwork, isNetwork,
@ -253,6 +256,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
textTracks: _textTracks, textTracks: _textTracks,
textTracksAllowChunklessPreparation: textTracksAllowChunklessPreparation:
resolvedSource.textTracksAllowChunklessPreparation, resolvedSource.textTracksAllowChunklessPreparation,
minLoadRetryCount: _minLoadRetryCount,
}; };
}, },
[ [
@ -261,6 +265,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
contentStartTime, contentStartTime,
drm, drm,
localSourceEncryptionKeyScheme, localSourceEncryptionKeyScheme,
minLoadRetryCount,
source?.cmcd, source?.cmcd,
textTracks, textTracks,
], ],

View File

@ -50,6 +50,7 @@ export type VideoSrc = Readonly<{
textTracksAllowChunklessPreparation?: boolean; // android textTracksAllowChunklessPreparation?: boolean; // android
textTracks?: TextTracks; textTracks?: TextTracks;
ad?: AdsConfig; ad?: AdsConfig;
minLoadRetryCount?: Int32; // Android
}>; }>;
type DRMType = WithDefault<string, 'widevine'>; type DRMType = WithDefault<string, 'widevine'>;
@ -362,7 +363,6 @@ export interface VideoNativeProps extends ViewProps {
disableDisconnectError?: boolean; // Android disableDisconnectError?: boolean; // Android
focusable?: boolean; // Android focusable?: boolean; // Android
hideShutterView?: boolean; // Android hideShutterView?: boolean; // Android
minLoadRetryCount?: Int32; // Android
reportBandwidth?: boolean; //Android reportBandwidth?: boolean; //Android
subtitleStyle?: SubtitleStyle; // android subtitleStyle?: SubtitleStyle; // android
viewType?: Int32; // Android viewType?: Int32; // Android

View File

@ -39,6 +39,7 @@ export type ReactVideoSourceProperties = {
textTracksAllowChunklessPreparation?: boolean; textTracksAllowChunklessPreparation?: boolean;
textTracks?: TextTracks; textTracks?: TextTracks;
ad?: AdConfig; ad?: AdConfig;
minLoadRetryCount?: number; // Android
}; };
export type ReactVideoSource = Readonly< export type ReactVideoSource = Readonly<
@ -305,6 +306,7 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
fullscreenOrientation?: EnumValues<FullscreenOrientationType>; // iOS fullscreenOrientation?: EnumValues<FullscreenOrientationType>; // iOS
hideShutterView?: boolean; // Android hideShutterView?: boolean; // Android
ignoreSilentSwitch?: EnumValues<IgnoreSilentSwitchType>; // iOS ignoreSilentSwitch?: EnumValues<IgnoreSilentSwitchType>; // iOS
/** @deprecated Use source.minLoadRetryCount */
minLoadRetryCount?: number; // Android minLoadRetryCount?: number; // Android
maxBitRate?: number; maxBitRate?: number;
mixWithOthers?: EnumValues<MixWithOthersType>; // iOS mixWithOthers?: EnumValues<MixWithOthersType>; // iOS