Expose DefaultLoadControl parameters Android
This commit is contained in:
parent
2087d0a150
commit
092ba33e95
8
Video.js
8
Video.js
@ -11,7 +11,13 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
});
|
||||
|
||||
export { TextTrackType };
|
||||
const {
|
||||
ExoPlayerConfig
|
||||
} = NativeModules
|
||||
|
||||
const VideoPlayerConfig = Platform.OS === "android" ? ExoPlayerConfig : undefined;
|
||||
|
||||
export { TextTrackType, VideoPlayerConfig};
|
||||
|
||||
export default class Video extends Component {
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -58,6 +58,7 @@ import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
@ -90,6 +91,11 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
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 Handler mainHandler;
|
||||
@ -234,7 +240,9 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
if (player == null) {
|
||||
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
|
||||
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
|
||||
player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl());
|
||||
DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
|
||||
DefaultLoadControl defaultLoadControl = new DefaultLoadControl(allocator, minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, -1, true);
|
||||
player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, defaultLoadControl);
|
||||
player.addListener(this);
|
||||
player.setMetadataOutput(this);
|
||||
exoPlayerView.setPlayer(player);
|
||||
@ -931,4 +939,21 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
public void setUseTextureView(boolean useTextureView) {
|
||||
exoPlayerView.setUseTextureView(useTextureView);
|
||||
}
|
||||
|
||||
|
||||
public static void setMinBufferMs(int newMinBufferMs) {
|
||||
minBufferMs = newMinBufferMs;
|
||||
}
|
||||
|
||||
public static void setMaxBufferMs(int newMaxBufferMs) {
|
||||
maxBufferMs = newMaxBufferMs;
|
||||
}
|
||||
|
||||
public static void setBufferForPlaybackMs(int newBufferForPlaybackMs) {
|
||||
bufferForPlaybackMs = newBufferForPlaybackMs;
|
||||
}
|
||||
|
||||
public static void setBufferForPlaybackAfterRebufferMs(int newBufferForPlaybackAfterRebufferMs) {
|
||||
bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.brentvatne.react;
|
||||
|
||||
import com.brentvatne.exoplayer.ReactExoplayerViewManager;
|
||||
import com.brentvatne.exoplayer.ExoPlayerConfig;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -14,7 +16,11 @@ public class ReactVideoPackage implements ReactPackage {
|
||||
|
||||
@Override
|
||||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
||||
return Collections.emptyList();
|
||||
List<NativeModule> modules = new ArrayList<>();
|
||||
|
||||
modules.add(new ExoPlayerConfig(reactContext));
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
// Deprecated RN 0.47
|
||||
|
Loading…
Reference in New Issue
Block a user