From 92b5235035e3a35f0328057d65cf75026d8f9061 Mon Sep 17 00:00:00 2001 From: Aiirondev Date: Mon, 1 Jun 2026 12:32:42 +0200 Subject: [PATCH] feat: Improve mobile video playback for barcode scanning with autoplay and mute settings --- Web/static/js/scanner.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Web/static/js/scanner.js b/Web/static/js/scanner.js index c0ee5da..06e73fc 100644 --- a/Web/static/js/scanner.js +++ b/Web/static/js/scanner.js @@ -119,6 +119,21 @@ class HybridScanner { // Make video element visible (ensure it's not hidden by display: none) this.state.videoElement.style.display = 'block'; + // Ensure autoplay works on mobile by muting and setting playsInline + try { + this.state.videoElement.muted = true; + this.state.videoElement.autoplay = true; + this.state.videoElement.playsInline = true; + // Some browsers require explicit play() after setting srcObject + const p = this.state.videoElement.play(); + if (p && p.then) { + p.catch(() => { + // ignore play promise rejection (user gesture required on some browsers) + }); + } + } catch (e) { + // ignore + } // Initialize ZXing reader const hints = new Map(); @@ -158,6 +173,16 @@ class HybridScanner { this.state.videoElement.style.display = 'none'; } + // Reset ZXing reader to stop any internal loops + try { + if (this.state.reader && typeof this.state.reader.reset === 'function') { + this.state.reader.reset(); + } + } catch (e) { + // ignore + } + this.state.reader = null; + this.removeKeyboardInput(); }