diff --git a/public/index.js b/public/index.js index 7bfe6a4..caf9f36 100644 --- a/public/index.js +++ b/public/index.js @@ -41,6 +41,25 @@ } window.isMobile = window.mobilecheck() + // Context bullshit + let playerContext = [] + + window.resumeContexts = function () { + for (let i in playerContext) { + let ctx = playerContext[i] + if (ctx && ctx.resume) { + ctx.resume().catch(function (e) { + console.error(e) + alert('Failed to play:', e.message) + }) + } + } + } + + window.attachAudioContext = function (ctx) { + playerContext.push(ctx) + } + // Seconds into HH:MM:SS function toHHMMSS (numbr) { let secNum = parseInt(numbr, 10) // don't forget the second param @@ -331,6 +350,8 @@ audio.src = '/api/serve/by-id/' + id audio.play() + window.resumeAudioContexts() + updateQT(q) nowPlaying = id diff --git a/public/player.js b/public/player.js index 69937d5..5e8e46d 100644 --- a/public/player.js +++ b/public/player.js @@ -12,6 +12,8 @@ var volBar = document.querySelector('#player-volbar .seek-inner') var volElem = document.querySelector('.volume') + var playerContext = [] + // Seconds into HH:MM:SS function toHHMMSS (numbr) { let secNum = parseInt(numbr, 10) // don't forget the second param @@ -170,6 +172,7 @@ } else { audio.pause() } + window.resumeAudioContexts() }, false) mute.addEventListener('click', function (e) { diff --git a/public/visuals.js b/public/visuals.js index e271b9d..bd17873 100644 --- a/public/visuals.js +++ b/public/visuals.js @@ -63,6 +63,7 @@ renderFrame() window.addEventListener('resize', convenientSizer) + window.attachAudioContext(context) convenientSizer() })()