Handling exceptions in video player
Reviewed By: furdei Differential Revision: D5958119 fbshipit-source-id: 79b431a8422d60134890d44e99c358a07a5adc5b
This commit is contained in:
parent
4e5d50d6ad
commit
9424cd7e8f
|
@ -420,21 +420,31 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
|
||||||
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
||||||
retriever.setDataSource(photoDescriptor.getFileDescriptor());
|
retriever.setDataSource(photoDescriptor.getFileDescriptor());
|
||||||
|
|
||||||
if (width <= 0 || height <= 0) {
|
try {
|
||||||
width =
|
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(
|
Integer.parseInt(
|
||||||
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
|
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
|
||||||
height =
|
int playableDuration = timeInMillisec / 1000;
|
||||||
Integer.parseInt(
|
image.putInt("playableDuration", playableDuration);
|
||||||
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
|
} 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) {
|
} catch (IOException e) {
|
||||||
FLog.e(ReactConstants.TAG, "Could not get video metadata for " + photoUri.toString(), e);
|
FLog.e(ReactConstants.TAG, "Could not get video metadata for " + photoUri.toString(), e);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue