CameraPreview is not working properly in Ionic 3 app.
See original GitHub issueI used tutorials to build a camera app. I want to show a camera preview inside of first ion-slide tag, then load ‘map’ in the second slide. and after taking the photo swipe to next slide. but camera preview is load in fullscreen and fab buttons didn’t show on camera preview. tapping sounds like taking the photo but also back button is not working.
ts
export class HomePage {
public LatLng: any;
public map: any;
public picture;
public shouldHide = false;
localized: boolean = false;
private cameraPreviewOpts = {
x: 0,
y: 0,
width: window.screen.width,
height: window.screen.height,
camera: 'rear',
toBack: false,
tapPhoto: true,
tapFocus: false,
previewDrag: false
};
@ViewChild('slides') slides: Slides;
constructor(public navCtrl: NavController, public navParams: NavParams,
public diagnostic: Diagnostic,
private cameraPreview: CameraPreview
) {
this.checkPermissions();
}
initializePreview() {
this.cameraPreview.startCamera(this.cameraPreviewOpts).then(
(res) => {
console.log(res)
},
(err) => {
console.log(err)
});
}
checkPermissions() {
this.diagnostic.isCameraAuthorized().then((authorized) => {
if (authorized){
this.initializePreview();}
else {
this.diagnostic.requestCameraAuthorization().then((status) => {
if (status == this.diagnostic.permissionStatus.GRANTED)
this.initializePreview();
else {
this.toastCtrl.show(
'Cannot access camera',
'5000',
'bottom',
).subscribe(
toast => {
console.log(toast);
}
);
}
});
}
});
}
takePhoto() {
const pictureOpts: CameraPreviewPictureOptions = {
width: 1280,
height: 1280,
quality: 85
};
this.cameraPreview.takePicture(pictureOpts).then((imageData) => {
this.picture = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
console.log(err);
this.picture = 'assets/img/test.jpg';
});
}
ionViewWillEnter() {
this.slides.update();
this.slides._allowSwipeToNext = false;
this.slides._allowSwipeToPrev = false;
}
ngOnInit(): void {
this.drawMap();
}
}
html
<ion-content no-bounce>
<ion-slides #slides (ionSlideWillChange)="onSlideChangeStart($event)" pager dir="rtl">
<ion-slide>
<ion-fab right top>
<button ion-fab color="secondary" (click)="changeEffect()">
<ion-icon name="md-color-wand"></ion-icon>
</button>
</ion-fab>
<ion-fab right bottom>
<button ion-fab color="primary" (click)="takePhoto()">
<ion-icon name="md-camera"></ion-icon>
</button>
</ion-fab>
</ion-slide>
<h2> slide 2 </h2>
</ion-slide>
output
Issue Analytics
- State:
- Created 5 years ago
- Comments:14
Top Results From Across the Web
CameraPreview is not working properly - ionic-v3
I used tutorials to build a camera app. I want to show a camera preview inside of first ion-slide tag, then load 'map'...
Read more >Problem with Camera Preview Plugin (ionic 3) - Stack Overflow
I'm developing an ionic 3 application in which I need to show the camera interface inside the app screen and camera-preview seems to...
Read more >[Solved]-Cordova Plugin Camera Preview ...
Coding example for the question Cordova Plugin Camera Preview NSCameraUsageDescription is not working (Ionic 3)
Read more >@ionic-native/camera-preview - npm package | Snyk
This plugin is still in beta stage and may not work as expected. Please submit any issues to the plugin repo. $ ionic...
Read more >cordova-plugin-camera-preview-alwaysmkt - npm
iOS Quirks · It is not possible to use your computers webcam during testing in the simulator, you must device test. · If...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem for me wasn’t z-index, that was my first attempt, but if the issue had something to do with z-index, it would not work on iOS either. But that behavior was only happening in android devices. It’s a bug at plugin code generated for android. The only way I found to solve this was to edit java file at plugin folder… I don’t remember where I read that solution, if I did, I would make reference here, but here’s what I’ve done:
at line 286 replace that if content for this:
That solved the problem for me. Hope that works for you if someone is still stuck on this.
A PR was recently merged which contained some fixes similar to this. https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview/pull/568
Please try using master branch with the latest changes