Fetching video length
Reviewed By: furdei Differential Revision: D5596545 fbshipit-source-id: ae29bc27579f2d06b1281e677c1aa820d50d9ee2
This commit is contained in:
parent
16afaa185c
commit
6a6e6019c0
|
@ -88,9 +88,7 @@ const getPhotosReturnChecker = createStrictShapeTypeChecker({
|
||||||
height: PropTypes.number.isRequired,
|
height: PropTypes.number.isRequired,
|
||||||
width: PropTypes.number.isRequired,
|
width: PropTypes.number.isRequired,
|
||||||
isStored: PropTypes.bool,
|
isStored: PropTypes.bool,
|
||||||
// TODO (nivethavadivelu) Need to add changes to Android before
|
playableDuration: PropTypes.number.isRequired,
|
||||||
// setting it as required
|
|
||||||
playableDuration: PropTypes.number,
|
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
timestamp: PropTypes.number.isRequired,
|
timestamp: PropTypes.number.isRequired,
|
||||||
location: createStrictShapeTypeChecker({
|
location: createStrictShapeTypeChecker({
|
||||||
|
|
|
@ -411,30 +411,46 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
|
||||||
width = photos.getInt(widthIndex);
|
width = photos.getInt(widthIndex);
|
||||||
height = photos.getInt(heightIndex);
|
height = photos.getInt(heightIndex);
|
||||||
}
|
}
|
||||||
if (width <= 0 || height <= 0) {
|
|
||||||
|
if (assetType != null
|
||||||
|
&& assetType.equals("Videos")
|
||||||
|
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||||
try {
|
try {
|
||||||
AssetFileDescriptor photoDescriptor = resolver.openAssetFileDescriptor(photoUri, "r");
|
AssetFileDescriptor photoDescriptor = resolver.openAssetFileDescriptor(photoUri, "r");
|
||||||
if (assetType != null
|
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
||||||
&& assetType.equals("Videos")
|
retriever.setDataSource(photoDescriptor.getFileDescriptor());
|
||||||
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
|
||||||
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
if (width <= 0 || height <= 0) {
|
||||||
retriever.setDataSource(photoDescriptor.getFileDescriptor());
|
|
||||||
width =
|
width =
|
||||||
Integer.parseInt(
|
Integer.parseInt(
|
||||||
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
|
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
|
||||||
height =
|
height =
|
||||||
Integer.parseInt(
|
Integer.parseInt(
|
||||||
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
|
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
|
||||||
retriever.release();
|
|
||||||
} else {
|
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
||||||
// Set inJustDecodeBounds to true so we don't actually load the Bitmap, but only get its
|
|
||||||
// dimensions instead.
|
|
||||||
options.inJustDecodeBounds = true;
|
|
||||||
BitmapFactory.decodeFileDescriptor(photoDescriptor.getFileDescriptor(), null, options);
|
|
||||||
width = options.outWidth;
|
|
||||||
height = options.outHeight;
|
|
||||||
}
|
}
|
||||||
|
int timeInMillisec =
|
||||||
|
Integer.parseInt(
|
||||||
|
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
|
||||||
|
int playableDuration = timeInMillisec / 1000;
|
||||||
|
image.putInt("playableDuration", playableDuration);
|
||||||
|
retriever.release();
|
||||||
|
photoDescriptor.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
FLog.e(ReactConstants.TAG, "Could not get video metadata for " + photoUri.toString(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
try {
|
||||||
|
AssetFileDescriptor photoDescriptor = resolver.openAssetFileDescriptor(photoUri, "r");
|
||||||
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
|
// Set inJustDecodeBounds to true so we don't actually load the Bitmap, but only get its
|
||||||
|
// dimensions instead.
|
||||||
|
options.inJustDecodeBounds = true;
|
||||||
|
BitmapFactory.decodeFileDescriptor(photoDescriptor.getFileDescriptor(), null, options);
|
||||||
|
width = options.outWidth;
|
||||||
|
height = options.outHeight;
|
||||||
photoDescriptor.close();
|
photoDescriptor.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
FLog.e(ReactConstants.TAG, "Could not get width/height for " + photoUri.toString(), e);
|
FLog.e(ReactConstants.TAG, "Could not get width/height for " + photoUri.toString(), e);
|
||||||
|
|
Loading…
Reference in New Issue