-
Notifications
You must be signed in to change notification settings - Fork 24.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support videos in Android CameraRoll.getPhotos #11877
Conversation
By analyzing the blame information on this pull request, we identified @AaaChiuuu and @corbt to be potential reviewers. |
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@@ -279,6 +286,19 @@ protected void doInBackgroundGuarded(Void... params) { | |||
selection.append(" AND " + SELECTION_BUCKET); | |||
selectionArgs.add(mGroupName); | |||
} | |||
if (!TextUtils.isEmpty(mAssetType)) { | |||
if(mAssetType.equals("Videos")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you compare against a constant here instead of the string, "Videos"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do i need to to upgrade my RN to 0.47.2. because below version doesn't have any video support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR was not merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using RN version 0.45.0. Video support is not there in 0.45.0. What should I do. Please let me know
@@ -226,6 +228,7 @@ public void getPhotos(final ReadableMap params, final Promise promise) { | |||
int first = params.getInt("first"); | |||
String after = params.hasKey("after") ? params.getString("after") : null; | |||
String groupName = params.hasKey("groupName") ? params.getString("groupName") : null; | |||
String assetType = params.hasKey("assetType") ? params.getString("assetType") : "Photos"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use a constant here instead of "Photos"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean using a constant in Java or exporting the constant to JS? Because I found that the iOS companion didn't export constants to JS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant using a constant in Java, but after taking another look at this file, it seems like that would be against convention. Disregard.
@@ -294,7 +314,7 @@ protected void doInBackgroundGuarded(Void... params) { | |||
// an SQLite DB and forwards parameters to it without doing any parsing / validation. | |||
try { | |||
Cursor photos = resolver.query( | |||
Images.Media.EXTERNAL_CONTENT_URI, | |||
MediaStore.Files.getContentUri("external"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this change is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because querying against Images.Media.EXTERNAL_CONTENT_URI
will only gives you images. So we need to query against the "whole external content uri" and use MediaStore.Files.FileColumns.MEDIA_TYPE
to filter out what we need, either photos or videos or both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved. It looks like tests are not passing at this time, however.
I am not very familiar with RN's test suite. Is there something I should do here? |
@@ -347,12 +367,13 @@ private static void putEdges( | |||
int heightIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(Images.Media.HEIGHT) : -1; | |||
int longitudeIndex = photos.getColumnIndex(Images.Media.LONGITUDE); | |||
int latitudeIndex = photos.getColumnIndex(Images.Media.LATITUDE); | |||
int dataIndex = photos.getColumnIndex(MediaStore.MediaColumns.DATA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable should not be called photos
anymore since it's either photos or vides, correct? How about media
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is dataIndex
needed when it wasn't needed previously. Please add a comment above this line explaining what dataIndex
is and why it's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to limit the amount of changes to functional parts only. There are quite a few things that can be improved but I am just afraid to expand the scope of this PR too much.
dataIndex is needed for extracting the uri of the file. I found this the easiest way to reliably obtain the file uri.
@@ -279,6 +286,19 @@ protected void doInBackgroundGuarded(Void... params) { | |||
selection.append(" AND " + SELECTION_BUCKET); | |||
selectionArgs.add(mGroupName); | |||
} | |||
if (!TextUtils.isEmpty(mAssetType)) { | |||
if(mAssetType.equals("Videos")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Space after if
if(mAssetType.equals("Videos")) { | ||
selection.append(" AND " + MediaStore.Files.FileColumns.MEDIA_TYPE + " = " | ||
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO); | ||
} else if(mAssetType.equals("Photos")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after if
@@ -248,6 +252,7 @@ public void getPhotos(final ReadableMap params, final Promise promise) { | |||
private final int mFirst; | |||
private final @Nullable String mAfter; | |||
private final @Nullable String mGroupName; | |||
private final @Nullable String mAssetType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove @Nullable
from here because your code below expects it's always "Photos" or "Videos".
@Nullable ReadableArray mimeTypes, | ||
Promise promise) { | ||
super(context); | ||
mContext = context; | ||
mFirst = first; | ||
mAfter = after; | ||
mGroupName = groupName; | ||
mAssetType = assetType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validation: Throw a NPE if null
or an empty string is passed.
@@ -256,13 +261,15 @@ private GetPhotosTask( | |||
int first, | |||
@Nullable String after, | |||
@Nullable String groupName, | |||
@Nullable String assetType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove @Nullable
.
@@ -279,6 +286,19 @@ protected void doInBackgroundGuarded(Void... params) { | |||
selection.append(" AND " + SELECTION_BUCKET); | |||
selectionArgs.add(mGroupName); | |||
} | |||
if (!TextUtils.isEmpty(mAssetType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be empty - correct? Otherwise the code below won't filter photos or videos. What would the method return then?
Uri photoUri = Uri.withAppendedPath( | ||
Images.Media.EXTERNAL_CONTENT_URI, | ||
photos.getString(idIndex)); | ||
Uri photoUri = Uri.parse("file://" + photos.getString(dataIndex)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why get rid of the EXTERNAL_CONTENT_URI
here and not use MediaStore.Files.getContentUri("external")
like above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it simply won't work to append the id directly to the external content uri.
is this issue already resolved? |
@kevinresol @mkonicek Would it be possible to make headway on this? As far as I can see videos still don't show from the camera roll. |
Sorry but I can't maintain this anymore. If anyone is interested feel free to fork from my branch and create another PR. |
Hey all. Please vote up to get it merged ASAP! |
Support getting videos for
CameraRoll.getPhotos()
on Android. Before this PR,assetType
is ignored in Android.