Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

kevinresol
Copy link
Contributor

Support getting videos for CameraRoll.getPhotos() on Android. Before this PR, assetType is ignored in Android.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @AaaChiuuu and @corbt to be potential reviewers.

@facebook-github-bot
Copy link
Contributor

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.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jan 13, 2017
@facebook-github-bot
Copy link
Contributor

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")) {
Copy link
Contributor

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"?

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

Copy link
Contributor

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.

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";
Copy link
Contributor

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"?

Copy link
Contributor Author

@kevinresol kevinresol Jan 21, 2017

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.

Copy link
Contributor

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"),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

hramos
hramos previously approved these changes Jan 23, 2017
Copy link
Contributor

@hramos hramos left a 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.

@kevinresol
Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor

@mkonicek mkonicek Feb 1, 2017

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.

Copy link
Contributor Author

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")) {
Copy link
Contributor

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")) {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

@mkonicek mkonicek Feb 1, 2017

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 nullor an empty string is passed.

@@ -256,13 +261,15 @@ private GetPhotosTask(
int first,
@Nullable String after,
@Nullable String groupName,
@Nullable String assetType,
Copy link
Contributor

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)) {
Copy link
Contributor

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));
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@gevgasparyan
Copy link

is this issue already resolved?

@Ehesp
Copy link
Contributor

Ehesp commented Mar 29, 2017

@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.

@kevinresol
Copy link
Contributor Author

Sorry but I can't maintain this anymore. If anyone is interested feel free to fork from my branch and create another PR.

@kesha-antonov
Copy link
Contributor

Hey all.
I've created new PR: #13715

Please vote up to get it merged ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants