Permalink
Browse files

Fetching video length

Reviewed By: furdei

Differential Revision: D5596545

fbshipit-source-id: ae29bc27579f2d06b1281e677c1aa820d50d9ee2
  • Loading branch information...
Nivetha Singara Vadivelu authored and facebook-github-bot committed Aug 15, 2017
1 parent 25f2938 commit 400020215f67e8e60b739967e432f2b9d7e8496c
@@ -88,9 +88,7 @@ const getPhotosReturnChecker = createStrictShapeTypeChecker({
height: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
isStored: PropTypes.bool,
// TODO (nivethavadivelu) Need to add changes to Android before
// setting it as required
playableDuration: PropTypes.number,
playableDuration: PropTypes.number.isRequired,
}).isRequired,
timestamp: PropTypes.number.isRequired,
location: createStrictShapeTypeChecker({
@@ -411,30 +411,46 @@ private static boolean putImageInfo(
width = photos.getInt(widthIndex);
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 {
AssetFileDescriptor photoDescriptor = resolver.openAssetFileDescriptor(photoUri, "r");
if (assetType != null
&& assetType.equals("Videos")
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(photoDescriptor.getFileDescriptor());
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(photoDescriptor.getFileDescriptor());
if (width <= 0 || height <= 0) {
width =
Integer.parseInt(
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
height =
Integer.parseInt(
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();
} catch (IOException e) {
FLog.e(ReactConstants.TAG, "Could not get width/height for " + photoUri.toString(), e);

0 comments on commit 4000202

Please sign in to comment.