2015-10-30 17:43:18 -07:00
|
|
|
package com.brentvatne.react;
|
|
|
|
|
2015-11-11 13:37:35 -08:00
|
|
|
import com.brentvatne.react.ReactVideoView.Events;
|
2015-11-08 18:19:03 -08:00
|
|
|
import com.facebook.react.bridge.Arguments;
|
2015-10-30 17:43:18 -07:00
|
|
|
import com.facebook.react.bridge.ReadableMap;
|
2015-11-08 18:19:03 -08:00
|
|
|
import com.facebook.react.bridge.WritableMap;
|
2015-11-03 20:27:38 -08:00
|
|
|
import com.facebook.react.common.MapBuilder;
|
2016-02-02 18:22:33 +02:00
|
|
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
2015-10-30 17:43:18 -07:00
|
|
|
import com.facebook.react.uimanager.SimpleViewManager;
|
|
|
|
import com.facebook.react.uimanager.ThemedReactContext;
|
2015-11-08 18:19:03 -08:00
|
|
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
2015-11-05 17:13:35 -08:00
|
|
|
import com.yqritc.scalablevideoview.ScalableType;
|
2015-10-30 17:43:18 -07:00
|
|
|
|
2015-11-08 18:19:03 -08:00
|
|
|
import javax.annotation.Nullable;
|
2015-11-03 20:27:38 -08:00
|
|
|
import java.util.Map;
|
|
|
|
|
2015-11-09 17:54:15 -08:00
|
|
|
public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
|
2015-10-30 17:43:18 -07:00
|
|
|
|
|
|
|
public static final String REACT_CLASS = "RCTVideo";
|
|
|
|
|
2015-11-09 17:54:15 -08:00
|
|
|
public static final String PROP_SRC = "src";
|
|
|
|
public static final String PROP_SRC_URI = "uri";
|
|
|
|
public static final String PROP_SRC_TYPE = "type";
|
2018-01-13 21:29:53 +01:00
|
|
|
public static final String PROP_SRC_HEADERS = "requestHeaders";
|
2015-11-09 17:54:15 -08:00
|
|
|
public static final String PROP_SRC_IS_NETWORK = "isNetwork";
|
2016-09-14 12:28:06 +01:00
|
|
|
public static final String PROP_SRC_MAINVER = "mainVer";
|
|
|
|
public static final String PROP_SRC_PATCHVER = "patchVer";
|
2016-01-07 17:34:11 -03:00
|
|
|
public static final String PROP_SRC_IS_ASSET = "isAsset";
|
2015-11-09 17:54:15 -08:00
|
|
|
public static final String PROP_RESIZE_MODE = "resizeMode";
|
|
|
|
public static final String PROP_REPEAT = "repeat";
|
|
|
|
public static final String PROP_PAUSED = "paused";
|
|
|
|
public static final String PROP_MUTED = "muted";
|
|
|
|
public static final String PROP_VOLUME = "volume";
|
2018-06-05 23:04:20 +01:00
|
|
|
public static final String PROP_STEREO_PAN = "stereoPan";
|
2017-03-21 21:26:39 +01:00
|
|
|
public static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
|
2015-11-13 16:24:13 -08:00
|
|
|
public static final String PROP_SEEK = "seek";
|
|
|
|
public static final String PROP_RATE = "rate";
|
2018-07-17 17:47:19 -07:00
|
|
|
public static final String PROP_FULLSCREEN = "fullscreen";
|
2016-06-01 17:05:42 +02:00
|
|
|
public static final String PROP_PLAY_IN_BACKGROUND = "playInBackground";
|
2016-07-12 18:08:36 +02:00
|
|
|
public static final String PROP_CONTROLS = "controls";
|
2015-11-09 17:54:15 -08:00
|
|
|
|
2015-10-30 17:43:18 -07:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return REACT_CLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-09 17:54:15 -08:00
|
|
|
protected ReactVideoView createViewInstance(ThemedReactContext themedReactContext) {
|
|
|
|
return new ReactVideoView(themedReactContext);
|
2015-11-08 18:19:03 -08:00
|
|
|
}
|
2015-11-05 17:13:35 -08:00
|
|
|
|
2016-09-09 05:45:23 -07:00
|
|
|
@Override
|
|
|
|
public void onDropViewInstance(ReactVideoView view) {
|
|
|
|
super.onDropViewInstance(view);
|
|
|
|
view.cleanupMediaPlayerResources();
|
|
|
|
}
|
|
|
|
|
2015-11-08 18:19:03 -08:00
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public Map getExportedCustomDirectEventTypeConstants() {
|
2015-11-11 13:37:35 -08:00
|
|
|
MapBuilder.Builder builder = MapBuilder.builder();
|
|
|
|
for (Events event : Events.values()) {
|
|
|
|
builder.put(event.toString(), MapBuilder.of("registrationName", event.toString()));
|
|
|
|
}
|
|
|
|
return builder.build();
|
2015-11-03 20:27:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Nullable
|
2015-11-05 17:13:35 -08:00
|
|
|
public Map getExportedViewConstants() {
|
2015-11-03 20:27:38 -08:00
|
|
|
return MapBuilder.of(
|
2015-11-09 17:54:15 -08:00
|
|
|
"ScaleNone", Integer.toString(ScalableType.LEFT_TOP.ordinal()),
|
|
|
|
"ScaleToFill", Integer.toString(ScalableType.FIT_XY.ordinal()),
|
|
|
|
"ScaleAspectFit", Integer.toString(ScalableType.FIT_CENTER.ordinal()),
|
|
|
|
"ScaleAspectFill", Integer.toString(ScalableType.CENTER_CROP.ordinal())
|
2015-11-05 17:13:35 -08:00
|
|
|
);
|
2015-10-30 17:43:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@ReactProp(name = PROP_SRC)
|
2015-11-09 17:54:15 -08:00
|
|
|
public void setSrc(final ReactVideoView videoView, @Nullable ReadableMap src) {
|
2016-09-14 12:28:06 +01:00
|
|
|
int mainVer = src.getInt(PROP_SRC_MAINVER);
|
|
|
|
int patchVer = src.getInt(PROP_SRC_PATCHVER);
|
|
|
|
if(mainVer<0) { mainVer = 0; }
|
|
|
|
if(patchVer<0) { patchVer = 0; }
|
|
|
|
if(mainVer>0) {
|
|
|
|
videoView.setSrc(
|
|
|
|
src.getString(PROP_SRC_URI),
|
|
|
|
src.getString(PROP_SRC_TYPE),
|
2016-09-20 04:46:15 +04:00
|
|
|
src.getBoolean(PROP_SRC_IS_NETWORK),
|
|
|
|
src.getBoolean(PROP_SRC_IS_ASSET),
|
2017-10-02 20:11:41 +02:00
|
|
|
src.getMap(PROP_SRC_HEADERS),
|
2016-09-14 12:28:06 +01:00
|
|
|
mainVer,
|
|
|
|
patchVer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
videoView.setSrc(
|
|
|
|
src.getString(PROP_SRC_URI),
|
|
|
|
src.getString(PROP_SRC_TYPE),
|
|
|
|
src.getBoolean(PROP_SRC_IS_NETWORK),
|
2017-10-02 20:11:41 +02:00
|
|
|
src.getBoolean(PROP_SRC_IS_ASSET),
|
|
|
|
src.getMap(PROP_SRC_HEADERS)
|
|
|
|
);
|
2016-09-14 12:28:06 +01:00
|
|
|
}
|
2015-11-03 20:27:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@ReactProp(name = PROP_RESIZE_MODE)
|
2015-11-09 17:54:15 -08:00
|
|
|
public void setResizeMode(final ReactVideoView videoView, final String resizeModeOrdinalString) {
|
|
|
|
videoView.setResizeModeModifier(ScalableType.values()[Integer.parseInt(resizeModeOrdinalString)]);
|
2015-11-03 20:27:38 -08:00
|
|
|
}
|
|
|
|
|
2015-11-13 14:36:15 -08:00
|
|
|
@ReactProp(name = PROP_REPEAT, defaultBoolean = false)
|
2015-11-09 17:54:15 -08:00
|
|
|
public void setRepeat(final ReactVideoView videoView, final boolean repeat) {
|
|
|
|
videoView.setRepeatModifier(repeat);
|
2015-11-05 17:13:35 -08:00
|
|
|
}
|
|
|
|
|
2015-11-13 14:36:15 -08:00
|
|
|
@ReactProp(name = PROP_PAUSED, defaultBoolean = false)
|
2015-11-09 17:54:15 -08:00
|
|
|
public void setPaused(final ReactVideoView videoView, final boolean paused) {
|
|
|
|
videoView.setPausedModifier(paused);
|
2015-11-05 17:13:35 -08:00
|
|
|
}
|
2015-11-03 20:27:38 -08:00
|
|
|
|
2015-11-13 14:36:15 -08:00
|
|
|
@ReactProp(name = PROP_MUTED, defaultBoolean = false)
|
2015-11-09 17:54:15 -08:00
|
|
|
public void setMuted(final ReactVideoView videoView, final boolean muted) {
|
|
|
|
videoView.setMutedModifier(muted);
|
2015-11-03 20:27:38 -08:00
|
|
|
}
|
|
|
|
|
2015-11-13 14:36:15 -08:00
|
|
|
@ReactProp(name = PROP_VOLUME, defaultFloat = 1.0f)
|
2015-11-09 17:54:15 -08:00
|
|
|
public void setVolume(final ReactVideoView videoView, final float volume) {
|
|
|
|
videoView.setVolumeModifier(volume);
|
2015-10-30 17:43:18 -07:00
|
|
|
}
|
2015-11-13 16:24:13 -08:00
|
|
|
|
2018-06-05 23:04:20 +01:00
|
|
|
@ReactProp(name = PROP_STEREO_PAN)
|
|
|
|
public void setStereoPan(final ReactVideoView videoView, final float stereoPan) {
|
|
|
|
videoView.setStereoPan(stereoPan);
|
2018-06-05 02:25:46 +01:00
|
|
|
}
|
|
|
|
|
2017-03-21 21:26:39 +01:00
|
|
|
@ReactProp(name = PROP_PROGRESS_UPDATE_INTERVAL, defaultFloat = 250.0f)
|
|
|
|
public void setProgressUpdateInterval(final ReactVideoView videoView, final float progressUpdateInterval) {
|
|
|
|
videoView.setProgressUpdateInterval(progressUpdateInterval);
|
|
|
|
}
|
|
|
|
|
2015-11-13 16:24:13 -08:00
|
|
|
@ReactProp(name = PROP_SEEK)
|
|
|
|
public void setSeek(final ReactVideoView videoView, final float seek) {
|
|
|
|
videoView.seekTo(Math.round(seek * 1000.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
@ReactProp(name = PROP_RATE)
|
|
|
|
public void setRate(final ReactVideoView videoView, final float rate) {
|
|
|
|
videoView.setRateModifier(rate);
|
|
|
|
}
|
2016-06-01 17:05:42 +02:00
|
|
|
|
2018-07-17 17:47:19 -07:00
|
|
|
@ReactProp(name = PROP_FULLSCREEN, defaultBoolean = false)
|
|
|
|
public void setFullscreen(final ReactVideoView videoView, final boolean fullscreen) {
|
|
|
|
videoView.setFullscreen(fullscreen);
|
|
|
|
}
|
|
|
|
|
2016-06-01 17:05:42 +02:00
|
|
|
@ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false)
|
|
|
|
public void setPlayInBackground(final ReactVideoView videoView, final boolean playInBackground) {
|
|
|
|
videoView.setPlayInBackground(playInBackground);
|
|
|
|
}
|
2016-07-12 18:08:36 +02:00
|
|
|
|
|
|
|
@ReactProp(name = PROP_CONTROLS, defaultBoolean = false)
|
|
|
|
public void setControls(final ReactVideoView videoView, final boolean controls) {
|
|
|
|
videoView.setControls(controls);
|
|
|
|
}
|
2015-10-30 17:43:18 -07:00
|
|
|
}
|