WebRTC API允许您从Chrome打开手机上的手电筒功能。但是,您无法将其关闭。我已经在小米手机和三星设备上看到了这个问题。
function toggleFlash() {
let that = this;
const mediaStreamTrack = this.$refs.video.srcObject.getVideoTracks()[0];
const imageCapture = new window.ImageCapture(mediaStreamTrack);
imageCapture.getPhotoCapabilities().then(() => {
if (that.tourch === false) {
that.tourch = true;
mediaStreamTrack.applyConstraints({
advanced: [{ torch: true }]
});
} else if (that.tourch === true) {
that.tourch = false;
mediaStreamTrack.applyConstraints({
advanced: [{ torch: false }]
});
}
});
}