Permalink
Browse files

Allow Android videos to be shown in the CameraRoll selector

Summary:
Currently, Android camera roll videos cannot be retrieved in RN since

1) `CameraRollManager.java` doesn't do anything with the `assetType` param
2) Unspecifying MIME types doesn't show videos

This diff allows videos to be shown in the `CameraRoll.getPhotos(..)` call by reading `assetType`. Future diffs will come where the thumbnail and other info will be returned as well.

Reviewed By: furdei

Differential Revision: D5019202

fbshipit-source-id: a920273761b31f1a59ba6b8bc49c05852506829c
  • Loading branch information...
fred2028 authored and facebook-github-bot committed May 10, 2017
1 parent d40a7ea commit a324dfbd516f958a45032f4ce6f1a81ca7580967
@@ -31,6 +31,7 @@
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Video;
import android.text.TextUtils;
import com.facebook.common.logging.FLog;
@@ -213,6 +214,10 @@ public void onScanCompleted(String path, Uri uri) {
* mimeType (optional): restrict returned images to a specific mimetype (e.g.
* image/jpeg)
* </li>
* <li>
* assetType (optional): chooses between either photos or videos from the camera roll.
* Valid values are "Photos" or "Videos". Defaults to photos.
* </li>
* </ul>
* @param promise the Promise to be resolved when the photos are loaded; for a format of the
* parameters passed to this callback, see {@code getPhotosReturnChecker} in CameraRoll.js
@@ -222,6 +227,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") : null;
ReadableArray mimeTypes = params.hasKey("mimeTypes")
? params.getArray("mimeTypes")
: null;
@@ -235,6 +241,7 @@ public void getPhotos(final ReadableMap params, final Promise promise) {
after,
groupName,
mimeTypes,
assetType,
promise)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@@ -246,13 +253,15 @@ public void getPhotos(final ReadableMap params, final Promise promise) {
private final @Nullable String mGroupName;
private final @Nullable ReadableArray mMimeTypes;
private final Promise mPromise;
private final @Nullable String mAssetType;
private GetPhotosTask(
ReactContext context,
int first,
@Nullable String after,
@Nullable String groupName,
@Nullable ReadableArray mimeTypes,
@Nullable String assetType,
Promise promise) {
super(context);
mContext = context;
@@ -261,6 +270,7 @@ private GetPhotosTask(
mGroupName = groupName;
mMimeTypes = mimeTypes;
mPromise = promise;
mAssetType = assetType;
}
@Override
@@ -289,8 +299,12 @@ protected void doInBackgroundGuarded(Void... params) {
// setting a limit at all), but it works because this specific ContentProvider is backed by
// an SQLite DB and forwards parameters to it without doing any parsing / validation.
try {
Uri assetURI =
mAssetType != null && mAssetType.equals("Videos") ? Video.Media.EXTERNAL_CONTENT_URI :
Images.Media.EXTERNAL_CONTENT_URI;
Cursor photos = resolver.query(
Images.Media.EXTERNAL_CONTENT_URI,
assetURI,
PROJECTION,
selection.toString(),
selectionArgs.toArray(new String[selectionArgs.size()]),

1 comment on commit a324dfb

@kesha-antonov

This comment has been minimized.

Show comment
Hide comment
@kesha-antonov

kesha-antonov May 13, 2017

Hey!

Can you take a look at this PR? #13715
It's about support Video on Android.

kesha-antonov commented on a324dfb May 13, 2017

Hey!

Can you take a look at this PR? #13715
It's about support Video on Android.

Please sign in to comment.