Pass loadControl parameters as video props
This commit is contained in:
parent
092ba33e95
commit
dde27a320e
25
README.md
25
README.md
@ -229,6 +229,7 @@ var styles = StyleSheet.create({
|
|||||||
* [textTracks](#texttracks)
|
* [textTracks](#texttracks)
|
||||||
* [useTextureView](#usetextureview)
|
* [useTextureView](#usetextureview)
|
||||||
* [volume](#volume)
|
* [volume](#volume)
|
||||||
|
* [loadControl](#loadcontrol)
|
||||||
|
|
||||||
### Event props
|
### Event props
|
||||||
* [onAudioBecomingNoisy](#onaudiobecomingnoisy)
|
* [onAudioBecomingNoisy](#onaudiobecomingnoisy)
|
||||||
@ -479,6 +480,30 @@ Adjust the volume.
|
|||||||
|
|
||||||
Platforms: all
|
Platforms: all
|
||||||
|
|
||||||
|
#### loadControl
|
||||||
|
Adjust the load control parameters: minBufferMs, maxBufferMs, bufferForPlaybackMs and playbackAfterRebufferMs.
|
||||||
|
|
||||||
|
```
|
||||||
|
loadControl={{
|
||||||
|
minBufferMs: number,
|
||||||
|
maxBufferMs: number,
|
||||||
|
bufferForPlaybackMs: number,
|
||||||
|
bufferForPlaybackAfterRebufferMs: number,
|
||||||
|
}}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example with default values:
|
||||||
|
```
|
||||||
|
loadControl={{
|
||||||
|
minBufferMs: 15000,
|
||||||
|
maxBufferMs: 50000,
|
||||||
|
bufferForPlaybackMs: 2500,
|
||||||
|
bufferForPlaybackAfterRebufferMs: 5000,
|
||||||
|
}}
|
||||||
|
```
|
||||||
|
|
||||||
|
Platforms: AndroidExoplayer
|
||||||
|
|
||||||
### Event props
|
### Event props
|
||||||
|
|
||||||
#### onAudioBecomingNoisy
|
#### onAudioBecomingNoisy
|
||||||
|
14
Video.js
14
Video.js
@ -11,13 +11,7 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
export { TextTrackType };
|
||||||
ExoPlayerConfig
|
|
||||||
} = NativeModules
|
|
||||||
|
|
||||||
const VideoPlayerConfig = Platform.OS === "android" ? ExoPlayerConfig : undefined;
|
|
||||||
|
|
||||||
export { TextTrackType, VideoPlayerConfig};
|
|
||||||
|
|
||||||
export default class Video extends Component {
|
export default class Video extends Component {
|
||||||
|
|
||||||
@ -351,6 +345,12 @@ Video.propTypes = {
|
|||||||
paused: PropTypes.bool,
|
paused: PropTypes.bool,
|
||||||
muted: PropTypes.bool,
|
muted: PropTypes.bool,
|
||||||
volume: PropTypes.number,
|
volume: PropTypes.number,
|
||||||
|
loadControl: PropTypes.shape({
|
||||||
|
minBufferMs: PropTypes.number,
|
||||||
|
maxBufferMs: PropTypes.number,
|
||||||
|
bufferForPlaybackMs: PropTypes.number,
|
||||||
|
bufferForPlaybackAfterRebufferMs: PropTypes.number,
|
||||||
|
}),
|
||||||
stereoPan: PropTypes.number,
|
stereoPan: PropTypes.number,
|
||||||
rate: PropTypes.number,
|
rate: PropTypes.number,
|
||||||
playInBackground: PropTypes.bool,
|
playInBackground: PropTypes.bool,
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
package com.brentvatne.exoplayer;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.facebook.react.bridge.NativeModule;
|
|
||||||
import com.facebook.react.bridge.Promise;
|
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
|
||||||
import com.facebook.react.bridge.ReactContext;
|
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
|
||||||
|
|
||||||
|
|
||||||
public class ExoPlayerConfig extends ReactContextBaseJavaModule {
|
|
||||||
|
|
||||||
public ExoPlayerConfig(ReactApplicationContext reactContext) {
|
|
||||||
super(reactContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "ExoPlayerConfig";
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactMethod
|
|
||||||
public void setMinBufferMs(final int newMinBufferMs, final Promise promise) {
|
|
||||||
ReactExoplayerView.setMinBufferMs(newMinBufferMs);
|
|
||||||
promise.resolve(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactMethod
|
|
||||||
public void setMaxBufferMs(final int newMaxBufferMs, final Promise promise) {
|
|
||||||
ReactExoplayerView.setMaxBufferMs(newMaxBufferMs);
|
|
||||||
promise.resolve(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactMethod
|
|
||||||
public void setBufferForPlaybackMs(final int newBufferForPlaybackMs, final Promise promise) {
|
|
||||||
ReactExoplayerView.setBufferForPlaybackMs(newBufferForPlaybackMs);
|
|
||||||
promise.resolve(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactMethod
|
|
||||||
public void setBufferForPlaybackAfterRebufferMs(final int newBufferForPlaybackAfterRebufferMs, final Promise promise) {
|
|
||||||
ReactExoplayerView.setBufferForPlaybackAfterRebufferMs(newBufferForPlaybackAfterRebufferMs);
|
|
||||||
promise.resolve(null);
|
|
||||||
}
|
|
||||||
}
|
|
@ -91,11 +91,6 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
DEFAULT_COOKIE_MANAGER.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
|
DEFAULT_COOKIE_MANAGER.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
|
|
||||||
private static int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
|
|
||||||
private static int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
|
||||||
private static int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
|
||||||
|
|
||||||
private final VideoEventEmitter eventEmitter;
|
private final VideoEventEmitter eventEmitter;
|
||||||
|
|
||||||
private Handler mainHandler;
|
private Handler mainHandler;
|
||||||
@ -115,6 +110,11 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
private boolean isBuffering;
|
private boolean isBuffering;
|
||||||
private float rate = 1f;
|
private float rate = 1f;
|
||||||
|
|
||||||
|
private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
|
||||||
|
private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
|
||||||
|
private int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
||||||
|
private int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
||||||
|
|
||||||
// Props from React
|
// Props from React
|
||||||
private Uri srcUri;
|
private Uri srcUri;
|
||||||
private String extension;
|
private String extension;
|
||||||
@ -940,20 +940,13 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
exoPlayerView.setUseTextureView(useTextureView);
|
exoPlayerView.setUseTextureView(useTextureView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLoadControl(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs) {
|
||||||
public static void setMinBufferMs(int newMinBufferMs) {
|
player.release();
|
||||||
minBufferMs = newMinBufferMs;
|
this.player = null;
|
||||||
}
|
this.minBufferMs = newMinBufferMs;
|
||||||
|
this.maxBufferMs = newMaxBufferMs;
|
||||||
public static void setMaxBufferMs(int newMaxBufferMs) {
|
this.bufferForPlaybackMs = newBufferForPlaybackMs;
|
||||||
maxBufferMs = newMaxBufferMs;
|
this.bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs;
|
||||||
}
|
initializePlayer();
|
||||||
|
|
||||||
public static void setBufferForPlaybackMs(int newBufferForPlaybackMs) {
|
|
||||||
bufferForPlaybackMs = newBufferForPlaybackMs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setBufferForPlaybackAfterRebufferMs(int newBufferForPlaybackAfterRebufferMs) {
|
|
||||||
bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import com.facebook.react.common.MapBuilder;
|
|||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
import com.facebook.react.uimanager.ViewGroupManager;
|
import com.facebook.react.uimanager.ViewGroupManager;
|
||||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||||
|
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||||
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
|
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -38,6 +39,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
private static final String PROP_PAUSED = "paused";
|
private static final String PROP_PAUSED = "paused";
|
||||||
private static final String PROP_MUTED = "muted";
|
private static final String PROP_MUTED = "muted";
|
||||||
private static final String PROP_VOLUME = "volume";
|
private static final String PROP_VOLUME = "volume";
|
||||||
|
private static final String PROP_LOAD_CONTROL = "loadControl";
|
||||||
|
private static final String PROP_LOAD_CONTROL_MIN_BUFFER_MS = "minBufferMs";
|
||||||
|
private static final String PROP_LOAD_CONTROL_MAX_BUFFER_MS = "maxBufferMs";
|
||||||
|
private static final String PROP_LOAD_CONTROL_BUFFER_FOR_PLAYBACK_MS = "bufferForPlaybackMs";
|
||||||
|
private static final String PROP_LOAD_CONTROL_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = "bufferForPlaybackAfterRebufferMs";
|
||||||
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
|
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
|
||||||
private static final String PROP_SEEK = "seek";
|
private static final String PROP_SEEK = "seek";
|
||||||
private static final String PROP_RATE = "rate";
|
private static final String PROP_RATE = "rate";
|
||||||
@ -214,6 +220,25 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
videoView.setUseTextureView(useTextureView);
|
videoView.setUseTextureView(useTextureView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = PROP_LOAD_CONTROL)
|
||||||
|
public void setLoadControl(final ReactExoplayerView videoView, @Nullable ReadableMap loadControl) {
|
||||||
|
int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
|
||||||
|
int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
|
||||||
|
int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
||||||
|
int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
||||||
|
if (loadControl != null) {
|
||||||
|
minBufferMs = loadControl.hasKey(PROP_LOAD_CONTROL_MIN_BUFFER_MS)
|
||||||
|
? loadControl.getInt(PROP_LOAD_CONTROL_MIN_BUFFER_MS) : minBufferMs;
|
||||||
|
maxBufferMs = loadControl.hasKey(PROP_LOAD_CONTROL_MAX_BUFFER_MS)
|
||||||
|
? loadControl.getInt(PROP_LOAD_CONTROL_MAX_BUFFER_MS) : maxBufferMs;
|
||||||
|
bufferForPlaybackMs = loadControl.hasKey(PROP_LOAD_CONTROL_BUFFER_FOR_PLAYBACK_MS)
|
||||||
|
? loadControl.getInt(PROP_LOAD_CONTROL_BUFFER_FOR_PLAYBACK_MS) : bufferForPlaybackMs;
|
||||||
|
bufferForPlaybackAfterRebufferMs = loadControl.hasKey(PROP_LOAD_CONTROL_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS)
|
||||||
|
? loadControl.getInt(PROP_LOAD_CONTROL_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS) : bufferForPlaybackAfterRebufferMs;
|
||||||
|
videoView.setLoadControl(minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean startsWithValidScheme(String uriString) {
|
private boolean startsWithValidScheme(String uriString) {
|
||||||
return uriString.startsWith("http://")
|
return uriString.startsWith("http://")
|
||||||
|| uriString.startsWith("https://")
|
|| uriString.startsWith("https://")
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package com.brentvatne.react;
|
package com.brentvatne.react;
|
||||||
|
|
||||||
import com.brentvatne.exoplayer.ReactExoplayerViewManager;
|
import com.brentvatne.exoplayer.ReactExoplayerViewManager;
|
||||||
import com.brentvatne.exoplayer.ExoPlayerConfig;
|
|
||||||
import com.facebook.react.ReactPackage;
|
import com.facebook.react.ReactPackage;
|
||||||
import com.facebook.react.bridge.JavaScriptModule;
|
import com.facebook.react.bridge.JavaScriptModule;
|
||||||
import com.facebook.react.bridge.NativeModule;
|
import com.facebook.react.bridge.NativeModule;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.uimanager.ViewManager;
|
import com.facebook.react.uimanager.ViewManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -16,11 +14,7 @@ public class ReactVideoPackage implements ReactPackage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
||||||
List<NativeModule> modules = new ArrayList<>();
|
return Collections.emptyList();
|
||||||
|
|
||||||
modules.add(new ExoPlayerConfig(reactContext));
|
|
||||||
|
|
||||||
return modules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated RN 0.47
|
// Deprecated RN 0.47
|
||||||
|
Loading…
Reference in New Issue
Block a user