Autoplay Policy Changes mitigation attempt #1

This commit is contained in:
Evert Prants 2019-01-14 19:28:28 +02:00
parent 4a44e412e7
commit 6f06d70ff6
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 25 additions and 0 deletions

View File

@ -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

View File

@ -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) {

View File

@ -63,6 +63,7 @@
renderFrame()
window.addEventListener('resize', convenientSizer)
window.attachAudioContext(context)
convenientSizer()
})()