Skip to content

Support videos in Android CameraRoll.getPhotos - #11877

Closed
kevinresol wants to merge 2 commits into
react:masterfrom
kevinresol:cameraroll_video
Closed

kevinresol wants to merge 2 commits into
react:masterfrom
kevinresol:cameraroll_video

Conversation

@kevinresol

Copy link
Copy Markdown
Contributor

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

@facebook-github-bot

Copy link
Copy Markdown
Contributor

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

@facebook-github-bot

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

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")) {

Copy link
Copy Markdown
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"?

Copy link
Copy Markdown

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
Copy Markdown
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.

Copy link
Copy Markdown

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

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

@kevinresol kevinresol Jan 21, 2017 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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.

try {
Cursor photos = resolver.query(
Images.Media.EXTERNAL_CONTENT_URI,
MediaStore.Files.getContentUri("external"),

Copy link
Copy Markdown
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
Copy Markdown
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

@hramos hramos left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

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
Copy Markdown
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?

@mkonicek mkonicek Feb 1, 2017 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

selectionArgs.add(mGroupName);
}
if (!TextUtils.isEmpty(mAssetType)) {
if(mAssetType.equals("Videos")) {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if

private final int mFirst;
private final @Nullable String mAfter;
private final @Nullable String mGroupName;
private final @Nullable String mAssetType;

Copy link
Copy Markdown
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".

mFirst = first;
mAfter = after;
mGroupName = groupName;
mAssetType = assetType;

@mkonicek mkonicek Feb 1, 2017 •

Copy link
Copy Markdown
Contributor

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.

int first,
@Nullable String after,
@Nullable String groupName,
@Nullable String assetType,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove @Nullable.

selection.append(" AND " + SELECTION_BUCKET);
selectionArgs.add(mGroupName);
}
if (!TextUtils.isEmpty(mAssetType)) {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

is this issue already resolved?

@Ehesp

Ehesp commented Mar 29, 2017

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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
Copy Markdown
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