Expose DefaultLoadControl parameters Android

This commit is contained in:
Bryan van Wijk 2018-07-31 17:23:20 +02:00
parent 2087d0a150
commit 092ba33e95
4 changed files with 87 additions and 3 deletions

View File

@ -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 { export default class Video extends Component {

View File

@ -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);
}
}

View File

@ -58,6 +58,7 @@ import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.upstream.DataSource; 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.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
@ -90,6 +91,11 @@ 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;
@ -234,7 +240,9 @@ class ReactExoplayerView extends FrameLayout implements
if (player == null) { if (player == null) {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); 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.addListener(this);
player.setMetadataOutput(this); player.setMetadataOutput(this);
exoPlayerView.setPlayer(player); exoPlayerView.setPlayer(player);
@ -931,4 +939,21 @@ class ReactExoplayerView extends FrameLayout implements
public void setUseTextureView(boolean useTextureView) { public void setUseTextureView(boolean useTextureView) {
exoPlayerView.setUseTextureView(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;
}
} }

View File

@ -1,12 +1,14 @@
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;
@ -14,7 +16,11 @@ public class ReactVideoPackage implements ReactPackage {
@Override @Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { 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 // Deprecated RN 0.47