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;
|
2015-10-30 17:43:18 -07:00
|
|
|
import com.facebook.react.uimanager.ReactProp;
|
|
|
|
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";
|
|
|
|
public static final String PROP_SRC_IS_NETWORK = "isNetwork";
|
|
|
|
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";
|
2015-11-13 16:24:13 -08:00
|
|
|
public static final String PROP_SEEK = "seek";
|
|
|
|
public static final String PROP_RATE = "rate";
|
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
|
|
|
|
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) {
|
2015-11-08 18:19:03 -08:00
|
|
|
final ThemedReactContext themedReactContext = (ThemedReactContext) videoView.getContext();
|
|
|
|
final RCTEventEmitter eventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class);
|
2015-11-03 20:27:38 -08:00
|
|
|
|
|
|
|
try {
|
2015-11-09 17:54:15 -08:00
|
|
|
final String uriString = src.getString(PROP_SRC_URI);
|
|
|
|
final String type = src.getString(PROP_SRC_TYPE);
|
|
|
|
final boolean isNetwork = src.getBoolean(PROP_SRC_IS_NETWORK);
|
2015-11-03 20:27:38 -08:00
|
|
|
|
2015-11-12 19:27:12 -08:00
|
|
|
// TODO: Carry this inside videoView.setSrc
|
2015-11-08 18:19:03 -08:00
|
|
|
WritableMap writableSrc = Arguments.createMap();
|
2015-11-09 17:54:15 -08:00
|
|
|
writableSrc.putString(PROP_SRC_URI, uriString);
|
|
|
|
writableSrc.putString(PROP_SRC_TYPE, type);
|
|
|
|
writableSrc.putBoolean(PROP_SRC_IS_NETWORK, isNetwork);
|
2015-11-08 18:19:03 -08:00
|
|
|
WritableMap event = Arguments.createMap();
|
2015-11-09 17:54:15 -08:00
|
|
|
event.putMap(PROP_SRC, writableSrc);
|
2015-11-11 13:37:35 -08:00
|
|
|
eventEmitter.receiveEvent(videoView.getId(), Events.EVENT_LOAD_START.toString(), event);
|
|
|
|
|
2015-11-12 19:27:12 -08:00
|
|
|
videoView.setSrc(uriString, isNetwork);
|
2015-11-03 20:27:38 -08:00
|
|
|
} catch (Exception e) {
|
2015-11-12 19:27:12 -08:00
|
|
|
// TODO: Send onError
|
|
|
|
// TODO: Carry inside videoView.setSrc
|
2015-11-11 13:37:35 -08:00
|
|
|
e.printStackTrace();
|
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
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
2015-10-30 17:43:18 -07:00
|
|
|
}
|