first commit
This commit is contained in:
commit
69b647145f
58 files changed
+15796
No files matched your search
@@ -0,0 +1,21 @@
|
||||
let audioCtx: AudioContext | null = null
|
||||
|
||||
export function useAudioUnlock() {
|
||||
const unlocked = useState('audio-unlocked', () => false)
|
||||
|
||||
async function unlockAudio() {
|
||||
if (!import.meta.client) return
|
||||
try {
|
||||
const Ctx = window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext
|
||||
if (!audioCtx) audioCtx = new Ctx()
|
||||
if (audioCtx.state === 'suspended') {
|
||||
await audioCtx.resume()
|
||||
}
|
||||
unlocked.value = true
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return { unlocked, unlockAudio }
|
||||
}
|
||||
Reference in new issue
Block a user