Repository navigation
Support videos in Android CameraRoll.getPhotos - #11877
kevinresol wants to merge 2 commits into
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! |
| selectionArgs.add(mGroupName); | ||
| } | ||
| if (!TextUtils.isEmpty(mAssetType)) { | ||
| if(mAssetType.equals("Videos")) { |
There was a problem hiding this comment.
Can you compare against a constant here instead of the string, "Videos"?
There was a problem hiding this comment.
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.
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
| 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.
Can you use a constant here instead of "Photos"?
There was a problem hiding this comment.
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.
I meant using a constant in Java, but after taking another look at this file, it seems like that would be against convention. Disregard.
| try { | ||
| Cursor photos = resolver.query( | ||
| Images.Media.EXTERNAL_CONTENT_URI, | ||
| MediaStore.Files.getContentUri("external"), |
There was a problem hiding this comment.
Can you explain why this change is needed?
There was a problem hiding this comment.
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.
hramos
left a comment
There was a problem hiding this comment.
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? |
| 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.
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.
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.
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.
| selectionArgs.add(mGroupName); | ||
| } | ||
| if (!TextUtils.isEmpty(mAssetType)) { | ||
| if(mAssetType.equals("Videos")) { |
| if(mAssetType.equals("Videos")) { | ||
| selection.append(" AND " + MediaStore.Files.FileColumns.MEDIA_TYPE + " = " | ||
| + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO); | ||
| } else if(mAssetType.equals("Photos")) { |
| 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.
Remove @Nullable from here because your code below expects it's always "Photos" or "Videos".
| mFirst = first; | ||
| mAfter = after; | ||
| mGroupName = groupName; | ||
| mAssetType = assetType; |
There was a problem hiding this comment.
Validation: Throw a NPE if nullor an empty string is passed.
| int first, | ||
| @Nullable String after, | ||
| @Nullable String groupName, | ||
| @Nullable String assetType, |
| selection.append(" AND " + SELECTION_BUCKET); | ||
| selectionArgs.add(mGroupName); | ||
| } | ||
| if (!TextUtils.isEmpty(mAssetType)) { |
There was a problem hiding this comment.
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.
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.
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,assetTypeis ignored in Android.