Reputation: 97
I need to get video from device. I tried:
const fetchParams = {
first: 25000000,
assetType:'Videos', ->not working, gets only images
};
CameraRoll.getPhotos(fetchParams, this.storeImages, this.logImageError);
But got only images, also I tried:
var options = {
title: 'Select Image',
cancelButtonTitle: 'Cancel',
takePhotoButtonTitle: 'Take Photo...',
chooseFromLibraryButtonTitle: 'Choose from Library...',
mediaType: 'video', // 'photo' or 'video'
videoQuality: 'high', // 'low', 'medium', or 'high'
};
UIImagePickerManager.launchImageLibrary(options, (response) => {}
Upvotes: 2
Views: 1234
Reputation: 97
I added some rows
@ReactMethod
public void launchVideoLibrary(final ReadableMap options, final Callback callback){
response = Arguments.createMap();
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
mMainActivity.startActivityForResult(Intent.createChooser(intent, "Select Video"), REQUEST_LAUNCH_VIDEO_LIBRARY);
// response.putString("error", "Cannot launch video library");
// callback.invoke(response);
//
mCallback = callback;
}
And:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//robustness code
if (requestCode == REQUEST_LAUNCH_VIDEO_LIBRARY) {
Uri VideoData = data.getData();
String realPath = getRealPathFromURI(VideoData);
boolean isUrl = false;
if (realPath != null) {
try {
URL url = new URL(realPath);
isUrl = true;
} catch (MalformedURLException e) {
// not a url
}
}
if (realPath == null || isUrl) {
try {
File file = createFileFromURI(VideoData);
realPath = file.getAbsolutePath();
VideoData = Uri.fromFile(file);
}
catch(Exception e) {
response.putString("error", "Could not read video");
response.putString("uri", VideoData.toString());
mCallback.invoke(response);
return;
}
}
response.putString("uri", VideoData.toString());
response.putString("path", realPath);
mCallback.invoke(response);
return;
}
And in RN file:
UIImagePickerManager.launchVideoLibrary(options, (response) => {
console.log('Response = ', response);});
Upvotes: 0
Reputation: 655
try this :
Intent openGal = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(openGal, REQUEST_CODE);
this will open the gallery on your videos so you can choose one from them, then you can get the selected video uri in the onActivityResult
if (requestCode == 101 && resultCode == RESULT_OK) {
Uri VideoData = data.getData();
}
Upvotes: 1