Fetching video length
Reviewed By: furdei Differential Revision: D5596545 fbshipit-source-id: ae29bc27579f2d06b1281e677c1aa820d50d9ee2
This commit is contained in:
parent
25f2938344
commit
400020215f
|
@ -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 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue