Closed cloudSchulze closed 5 years ago
@triniwiz This error is getting really serious because it holds us back from releasing the android version for our customer.
Any news :( ?
HI i found the issue! I changed in videorecorder.android.js two lines of code:
// your code -> app.android.off(app.AndroidApplication.activityResultEvent); app.android.currentContext.onActivityResult = function (requestCode, resultCode, resultData) {
// my code -> app.android.off("activityResult"); app.android.on("activityResult", function (args) {
After that you can call "requestCode", "resultCode" and "resultData" in the args variable. I changed this two lines like the code of the nativescript-camera module. In camera.android.js you can find the same two lines of code. After changing this, it works like a charm.
protected _startRecording(options: Options = this.options): Promise<RecordResult> {
return new Promise((resolve, reject) => {
let data = null;
let file;
const pkgName = utils.ad.getApplication().getPackageName();
const state = android.os.Environment.getExternalStorageState();
if (state !== android.os.Environment.MEDIA_MOUNTED) {
return reject({event: 'failed'});
}
const intent = new android.content.Intent(
android.provider.MediaStore.ACTION_VIDEO_CAPTURE
);
intent.putExtra('android.intent.extra.videoQuality', options.hd ? 1 : 0);
if (options.position !== CameraPosition.NONE) {
intent.putExtra(
'android.intent.extras.CAMERA_FACING',
options.position === CameraPosition.BACK
? android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT
: android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK
);
}
if (options.size > 0) {
intent.putExtra(
android.provider.MediaStore.EXTRA_SIZE_LIMIT,
options.size * 1024 * 1024
);
}
const fileName = `VID_${+new Date()}.mp4`;
let path;
let tempPictureUri;
const sdkVersionInt = parseInt(platform.device.sdkVersion, 10);
if (options.saveToGallery) {
path = android.os.Environment.getExternalStoragePublicDirectory(
android.os.Environment.DIRECTORY_DCIM
).getAbsolutePath() + '/Camera';
} else {
path = app.android.currentContext.getExternalFilesDir(null).getAbsolutePath();
}
file = new java.io.File(path + '/' + fileName);
if (sdkVersionInt >= 21) {
tempPictureUri = (<any>android.support.v4.content).FileProvider.getUriForFile(
app.android.foregroundActivity, // or app.android.currentContext ??
`${pkgName}.provider`,
file
);
} else {
tempPictureUri = android.net.Uri.fromFile(file);
}
intent.putExtra(
android.provider.MediaStore.EXTRA_OUTPUT,
tempPictureUri
);
if (options.duration > 0) {
intent.putExtra(
android.provider.MediaStore.EXTRA_DURATION_LIMIT,
options.duration
);
}
if (
intent.resolveActivity(app.android.context.getPackageManager()) !=
null
) {
app.android.off("activityResult");
app.android.on("activityResult", function (args) {
if (args.requestCode === REQUEST_VIDEO_CAPTURE && args.resultCode === RESULT_OK) {
const mediaFile = args.resultData ? args.resultData.getData() : file;
if (options.saveToGallery) {
resolve({file: getRealPathFromURI(mediaFile)});
} else {
resolve({file: file.toString()});
}
} else if (args.resultCode === RESULT_CANCELED) {
reject({event: 'cancelled'});
} else {
reject({event: 'failed'});
}
});
app.android.foregroundActivity.startActivityForResult(
intent,
REQUEST_VIDEO_CAPTURE
);
} else {
reject({event: 'failed'});
}
});
}
}
Hi,
i think, i have found an issue. In my app there is a page, where the user can take pictures and record a video. The issue is that after recording a video with the nativescript-videorecorder, i can't take a picture with nativescript-camera anymore. The promise in camera.takePicture don't get back. No resolve and no reject. Can you help me :( ?
Here is my code:
After this
public onRecordVideo(): void { if (isAndroid) { permissions.requestPermission([ android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.CAMERA] ) .then(() => { this.recordVideo(); }).catch(err =>{ console.log("Error -> " + err.message); var toast = Toast.makeText(
Es ist ein Fehler aufgetreten! Bitte versuchen Sie es erneut!
); toast.show(); }); } else{ this.recordVideo(); }I can't do this ...
public onTakePicture(index : number){ if (isAndroid) { permissions.requestPermission([ android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.CAMERA]) .then(() => { this.takePicture(index); }).catch(err =>{ console.log("Error -> " + err.message); var toast = Toast.makeText(
Es ist ein Fehler aufgetreten! Bitte versuchen Sie es erneut!
); toast.show(); }); } else{ this.takePicture(index); } }private takePicture(index : number){ console.log("Take a picture ...") try{
camera.takePicture(this.camOptions). then((imageAsset) => {
console.log(imageAsset)
var image = new Image(); this.photos[index].imgUrl = imageAsset; }).catch(err => { console.log("Error -> " + err.message); var toast = Toast.makeText(
Es ist ein Fehler aufgetreten! Bitte versuchen Sie es erneut!
); toast.show(); }); } catch(err){ console.log("Error -> " + err.message); var toast = Toast.makeText(Es ist ein Fehler aufgetreten! Bitte versuchen Sie es erneut!
); toast.show(); } }This are my packages i use:
"dependencies": { "@angular/animations": "~6.0.6", "@angular/common": "~6.0.6", "@angular/compiler": "~6.0.6", "@angular/core": "~6.0.6", "@angular/forms": "~6.0.6", "@angular/http": "~6.0.6", "@angular/platform-browser": "~6.0.6", "@angular/platform-browser-dynamic": "~6.0.6", "@angular/router": "~6.0.6", "@nstudio/nativescript-camera-plus": "1.0.6", "font-awesome": "^4.7.0", "moment": "^2.22.2", "nativescript-angular": "~6.0.6", "nativescript-camera": "^4.0.2", "nativescript-iqkeyboardmanager": "^1.3.0", "nativescript-loading-indicator": "^2.4.0", "nativescript-localstorage": "^1.1.5", "nativescript-modal-datetimepicker": "^1.1.3", "nativescript-phone": "^1.3.1", "nativescript-plugin-firebase": "^6.4.1", "nativescript-theme-core": "~1.0.4", "nativescript-toast": "^1.4.6", "nativescript-ui-listview": "^3.5.11", "nativescript-videoplayer": "^4.2.0", "nativescript-videorecorder": "^3.0.0-alpha.11", "reflect-metadata": "~0.1.10", "rxjs": "~6.1.0", "tns-core-modules": "^4.2.0", "zone.js": "~0.8.18" }, "devDependencies": { "@angular/compiler-cli": "^6.1.3", "@ngtools/webpack": "6.1.0-rc.0", "babel-traverse": "^6.26.0", "babel-types": "^6.26.0", "babylon": "6.4.5", "lazy": "1.0.11", "nativescript-dev-typescript": "~0.7.0", "nativescript-dev-webpack": "~0.14.0", "typescript": "~2.7.2" }