Handling exceptions in video player

Reviewed By: furdei

Differential Revision: D5958119

fbshipit-source-id: 79b431a8422d60134890d44e99c358a07a5adc5b
This commit is contained in:
Nivetha Singara Vadivelu 2017-10-09 22:34:40 -07:00 committed by Facebook Github Bot
parent 4e5d50d6ad
commit 9424cd7e8f
1 changed files with 23 additions and 13 deletions

View File

@ -420,21 +420,31 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(photoDescriptor.getFileDescriptor());
if (width <= 0 || height <= 0) {
width =
try {
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));
}
int timeInMillisec =
Integer.parseInt(
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
height =
Integer.parseInt(
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
int playableDuration = timeInMillisec / 1000;
image.putInt("playableDuration", playableDuration);
} catch (NumberFormatException e) {
FLog.e(
ReactConstants.TAG,
"Number format exception occurred while trying to fetch video metadata for "
+ photoUri.toString(),
e);
return false;
} finally {
retriever.release();
photoDescriptor.close();
}
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;