mirror of
https://github.com/smittix/intercept.git
synced 2026-07-16 21:38:11 -07:00
Prompt user to enable audio playback
This commit is contained in:
@@ -27,6 +27,7 @@ let audioWebSocket = null;
|
|||||||
let audioQueue = [];
|
let audioQueue = [];
|
||||||
let isWebSocketAudio = false;
|
let isWebSocketAudio = false;
|
||||||
let audioFetchController = null;
|
let audioFetchController = null;
|
||||||
|
let audioUnlockRequested = false;
|
||||||
|
|
||||||
// Visualizer state
|
// Visualizer state
|
||||||
let visualizerContext = null;
|
let visualizerContext = null;
|
||||||
@@ -1861,9 +1862,8 @@ function toggleDirectListen() {
|
|||||||
audioPlayer.muted = false;
|
audioPlayer.muted = false;
|
||||||
audioPlayer.autoplay = true;
|
audioPlayer.autoplay = true;
|
||||||
audioPlayer.preload = 'auto';
|
audioPlayer.preload = 'auto';
|
||||||
// Ensure Chrome treats this as a user-initiated playback
|
|
||||||
audioPlayer.play().catch(() => {});
|
|
||||||
}
|
}
|
||||||
|
audioUnlockRequested = true;
|
||||||
// First press - start immediately, don't debounce
|
// First press - start immediately, don't debounce
|
||||||
startDirectListenImmediate();
|
startDirectListenImmediate();
|
||||||
}
|
}
|
||||||
@@ -2149,13 +2149,11 @@ async function _startDirectListenInternal() {
|
|||||||
// Wait for audio to be ready then play
|
// Wait for audio to be ready then play
|
||||||
audioPlayer.oncanplay = () => {
|
audioPlayer.oncanplay = () => {
|
||||||
console.log('[LISTEN] Audio can play');
|
console.log('[LISTEN] Audio can play');
|
||||||
audioPlayer.play().catch(e => console.warn('[LISTEN] Autoplay blocked:', e));
|
attemptAudioPlay(audioPlayer);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Also try to play immediately (some browsers need this)
|
// Also try to play immediately (some browsers need this)
|
||||||
audioPlayer.play().catch(e => {
|
attemptAudioPlay(audioPlayer);
|
||||||
console.log('[LISTEN] Initial play blocked, waiting for canplay');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fallback: if stream never starts, try fetch-based stream
|
// Fallback: if stream never starts, try fetch-based stream
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
@@ -2191,6 +2189,36 @@ async function _startDirectListenInternal() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function attemptAudioPlay(audioPlayer) {
|
||||||
|
if (!audioPlayer) return;
|
||||||
|
audioPlayer.play().then(() => {
|
||||||
|
hideAudioUnlock();
|
||||||
|
}).catch(() => {
|
||||||
|
// Autoplay likely blocked; show manual unlock
|
||||||
|
showAudioUnlock(audioPlayer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAudioUnlock(audioPlayer) {
|
||||||
|
const unlockBtn = document.getElementById('audioUnlockBtn');
|
||||||
|
if (!unlockBtn || !audioUnlockRequested) return;
|
||||||
|
unlockBtn.style.display = 'block';
|
||||||
|
unlockBtn.onclick = () => {
|
||||||
|
audioPlayer.muted = false;
|
||||||
|
audioPlayer.play().then(() => {
|
||||||
|
hideAudioUnlock();
|
||||||
|
}).catch(() => {});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideAudioUnlock() {
|
||||||
|
const unlockBtn = document.getElementById('audioUnlockBtn');
|
||||||
|
if (unlockBtn) {
|
||||||
|
unlockBtn.style.display = 'none';
|
||||||
|
}
|
||||||
|
audioUnlockRequested = false;
|
||||||
|
}
|
||||||
|
|
||||||
async function startFetchAudioStream(streamUrl, audioPlayer) {
|
async function startFetchAudioStream(streamUrl, audioPlayer) {
|
||||||
if (!window.MediaSource) {
|
if (!window.MediaSource) {
|
||||||
console.warn('[LISTEN] MediaSource not supported for fetch fallback');
|
console.warn('[LISTEN] MediaSource not supported for fetch fallback');
|
||||||
|
|||||||
@@ -1055,6 +1055,10 @@
|
|||||||
Audio Output</div>
|
Audio Output</div>
|
||||||
</div>
|
</div>
|
||||||
<audio id="scannerAudioPlayer" style="width: 100%; height: 28px;" controls></audio>
|
<audio id="scannerAudioPlayer" style="width: 100%; height: 28px;" controls></audio>
|
||||||
|
<button id="audioUnlockBtn" type="button"
|
||||||
|
style="display: none; margin-top: 8px; width: 100%; padding: 6px 10px; font-size: 10px; letter-spacing: 1px; background: var(--accent-cyan); color: #000; border: 1px solid var(--accent-cyan); border-radius: 4px; cursor: pointer;">
|
||||||
|
CLICK TO ENABLE AUDIO
|
||||||
|
</button>
|
||||||
<div style="display: flex; align-items: center; gap: 8px; margin-top: 8px;">
|
<div style="display: flex; align-items: center; gap: 8px; margin-top: 8px;">
|
||||||
<span style="font-size: 7px; color: var(--text-muted);">LEVEL</span>
|
<span style="font-size: 7px; color: var(--text-muted);">LEVEL</span>
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user