Skip to content

Commit 71e4e36

Browse files
committed
refactor: change functions plugin type
1 parent c8e3fb6 commit 71e4e36

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

android/src/main/java/com/brentvatne/exoplayer/RNVExoplayerPlugin.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,29 @@ interface RNVExoplayerPlugin : RNVPlugin {
2020

2121
/**
2222
* Optional function that allows the plugin to override the media data source factory,
23-
* which is responsible for loading the video data.
24-
* @return A lambda that takes a [Source] and the current [DataSource.Factory],
25-
* and returns a custom [DataSource.Factory], or null to use the default one.
23+
* which is responsible for loading media data.
24+
* @param source The media source being initialized.
25+
* @param mediaDataSourceFactory The current default data source factory.
26+
* @return A custom [DataSource.Factory] if override is needed, or null to use default.
2627
*/
27-
fun overrideMediaDataSourceFactory(): ((Source, DataSource.Factory) -> DataSource.Factory?)? = null
28+
fun overrideMediaDataSourceFactory(source: Source, mediaDataSourceFactory: DataSource.Factory): DataSource.Factory? = null
2829

2930
/**
30-
* Optional function that allows plugin to override the MediaItem builder
31-
* before the MediaItem is created.
32-
* @return A lambda that takes a [Source] and the current [MediaItem.Builder],
33-
* and returns a modified [MediaItem.Builder], or null if no override is needed.
31+
* Optional function that allows the plugin to modify the [MediaItem.Builder]
32+
* before the final [MediaItem] is created.
33+
* @param source The source from which the media item is being built.
34+
* @param mediaItemBuilder The default [MediaItem.Builder] instance.
35+
* @return A modified builder instance if override is needed, or null to use original.
3436
*/
35-
fun overrideMediaItemBuilder(): ((Source, MediaItem.Builder) -> MediaItem.Builder?)? = null
37+
fun overrideMediaItemBuilder(source: Source, mediaItemBuilder: MediaItem.Builder): MediaItem.Builder? = null
3638

3739
/**
3840
* Optional function that allows the plugin to control whether caching should be disabled
3941
* for a given video source.
40-
* @return A lambda that takes a [Source] and returns true if caching should be disabled,
41-
* or false to allow caching. Returns null to use the default behavior.
42+
* @param source The video source being loaded.
43+
* @return true to disable caching, false to keep it enabled.
4244
*/
43-
fun shouldDisableCache(): ((source: Source) -> Boolean)? = null
45+
fun shouldDisableCache(source: Source): Boolean = false
4446

4547
/**
4648
* Function called when a new player is created

android/src/main/java/com/brentvatne/react/ReactNativeVideoManager.kt

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,27 @@ class ReactNativeVideoManager : RNVPlugin {
8080

8181
fun overrideMediaDataSourceFactory(source: Source, mediaDataSourceFactory: DataSource.Factory): DataSource.Factory? {
8282
for (plugin in pluginList) {
83-
if (plugin !is RNVExoplayerPlugin) {
84-
continue
85-
}
83+
if (plugin !is RNVExoplayerPlugin) continue
8684

87-
val factory = plugin.overrideMediaDataSourceFactory()?.invoke(source, mediaDataSourceFactory)
88-
if (factory != null) {
89-
return factory
90-
}
85+
val factory = plugin.overrideMediaDataSourceFactory(source, mediaDataSourceFactory)
86+
if (factory != null) return factory
9187
}
9288
return null
9389
}
9490

9591
fun overrideMediaItemBuilder(source: Source, mediaItemBuilder: MediaItem.Builder): MediaItem.Builder? {
9692
for (plugin in pluginList) {
97-
if (plugin !is RNVExoplayerPlugin) {
98-
continue
99-
}
93+
if (plugin !is RNVExoplayerPlugin) continue
10094

101-
val builder = plugin.overrideMediaItemBuilder()?.invoke(source, mediaItemBuilder)
102-
if (builder != null) {
103-
return builder
104-
}
95+
val builder = plugin.overrideMediaItemBuilder(source, mediaItemBuilder)
96+
if (builder != null) return builder
10597
}
10698
return null
10799
}
108100

109101
fun shouldDisableCache(source: Source): Boolean {
110102
for (plugin in pluginList) {
111-
if (plugin !is RNVExoplayerPlugin) {
112-
continue
113-
}
114-
115-
val shouldDisable = plugin.shouldDisableCache()?.invoke(source)
116-
if (shouldDisable == true) {
103+
if (plugin is RNVExoplayerPlugin && plugin.shouldDisableCache(source)) {
117104
return true
118105
}
119106
}

0 commit comments

Comments
 (0)