Set Back Camera by Default
Closed this issue · 5 comments
DespertaWeb commented
Is there a way to set Back Cam by default?
Also is there a way to set the camera to fullscreen height? It doesn't work for me :(
VinceG commented
@DespertaWeb i don't think it's something that will be set by default. we can though pass in constraints to the object.
CavalcanteLeo commented
Is it possible to open/set the back camera by default? @VinceG @DespertaWeb
DespertaWeb commented
Despite I still thing that should be a must, apparently I don't think so. :(
abrichr commented
Here is how to open the back camera by default (tested on iPhone only):
<template>
<v-container fluid>
<vue-web-cam
@cameras="onCameras"
:autoplay="true"
:deviceId="deviceId"
ref="camera"
/>
</v-container>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { WebCam } from '@nickfan/vue-web-cam';
@Component({
components: {
'vue-web-cam': WebCam,
}
})
export default class MyCamera extends Vue {
private cameras = null;
get deviceId() {
const cameras: { deviceId: string, label: string }[] = this.cameras || [];
let rval = '';
if (cameras.length > 0) {
// try to identify the back camera
for (const { deviceId, label } of cameras) {
if (label.toLowerCase().includes('back')) {
rval = deviceId;
}
}
if (!rval.length) {
// otherwise just pick the first one
rval = cameras[0].deviceId;
}
}
console.log('deviceId() cameras:', cameras, 'rval:', rval);
return rval;
}
public onCameras(cameras) {
console.log('onCameras() cameras:', cameras);
this.cameras = cameras;
}
}
</script>
DespertaWeb commented
@abrichr could you please test it on other android phones, it would be amazing!