use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.
the class GLCanvas method capture.
private void capture() {
Bitmap capture = createSnapshot();
ReactContext reactContext = (ReactContext) getContext();
RCTEventEmitter eventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
for (CaptureConfig config : captureConfigs) {
String result = null, error = null;
boolean isPng = config.type.equals("png");
boolean isJpeg = !isPng && (config.type.equals("jpg") || config.type.equals("jpeg"));
boolean isWebm = !isPng && !isJpeg && config.type.equals("webm");
boolean isBase64 = config.format.equals("base64");
boolean isFile = !isBase64 && config.format.equals("file");
Bitmap.CompressFormat compressFormat = isPng ? Bitmap.CompressFormat.PNG : isJpeg ? Bitmap.CompressFormat.JPEG : isWebm ? Bitmap.CompressFormat.WEBP : null;
int quality = (int) (100 * config.quality);
if (compressFormat == null) {
error = "Unsupported capture type '" + config.type + "'";
} else if (isBase64) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
capture.compress(compressFormat, quality, baos);
String frame = "data:image/png;base64," + Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
baos.close();
result = frame;
} catch (Exception e) {
e.printStackTrace();
error = "Could not capture as base64: " + e.getMessage();
}
} else if (isFile) {
try {
FileOutputStream fileOutputStream = new FileOutputStream(config.filePath);
capture.compress(compressFormat, quality, fileOutputStream);
fileOutputStream.close();
result = "file://" + config.filePath;
} catch (Exception e) {
e.printStackTrace();
error = "Could not write file: " + e.getMessage();
}
} else {
error = "Unsupported capture format '" + config.format + "'";
}
WritableMap response = Arguments.createMap();
response.putMap("config", config.toMap());
if (error != null)
response.putString("error", error);
if (result != null)
response.putString("result", result);
eventEmitter.receiveEvent(getId(), "captureFrame", response);
}
captureConfigs = new ArrayList<>();
}
use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.
the class GLCanvas method dispatchOnLoad.
private void dispatchOnLoad() {
WritableMap event = Arguments.createMap();
ReactContext reactContext = (ReactContext) getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "load", event);
}
use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.
the class GLCanvas method dispatchOnProgress.
private void dispatchOnProgress(double progress, int loaded, int total) {
WritableMap event = Arguments.createMap();
event.putDouble("progress", Double.isNaN(progress) ? 0.0 : progress);
event.putInt("loaded", loaded);
event.putInt("total", total);
ReactContext reactContext = (ReactContext) getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "progress", event);
}
use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.
the class CaptureConfig method toMap.
public WritableMap toMap() {
WritableMap map = Arguments.createMap();
map.putString("format", format);
map.putString("type", type);
map.putString("filePath", filePath);
map.putDouble("quality", quality);
return map;
}
use of com.facebook.react.bridge.WritableMap in project react-native-android-video-editor by RZulfikri.
the class VideoSurfaceView method setSource.
public void setSource(String uri) {
videoUri = uri;
try {
mMediaPlayer.setDataSource(uri);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(uri);
videoHeight = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
videoWidth = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
rotation = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
if (videoWidth > 0 && videoHeight > 0) {
setDimension();
}
videoDuration = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
WritableMap event = Arguments.createMap();
event.putInt(Events.VIDEO_DURATION, videoDuration);
eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_VIDEO_DURATION.toString(), event);
retriever.release();
retriever = null;
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations