only get one click

This commit is contained in:
j 2021-10-25 09:23:06 +01:00
parent 0577adffb8
commit e4877ab3a9

View file

@ -16,51 +16,57 @@ function setVideoSrc(video, src) {
} }
video.src = src.replace('.webm', videoExtension) video.src = src.replace('.webm', videoExtension)
} }
var video
document.querySelector('a#play-fullscreen').addEventListener('click', event => { document.querySelector('a#play-fullscreen').addEventListener('click', event => {
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
var video = document.createElement('video') if (!video) {
video.classList.add('player') video = document.createElement('video')
setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm') video.classList.add('player')
video.controls = true setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm')
document.querySelector('main').appendChild(video) video.controls = true
video.style.display = 'none' document.querySelector('main').appendChild(video)
if (continueTimecode) { video.style.display = 'none'
video.currentTime = continueTimecode if (continueTimecode) {
} video.currentTime = continueTimecode
function enterFullscreen(event) {
if (video.webkitEnterFullScreen) {
video.webkitEnterFullScreen();
} else {
video.requestFullscreen().catch(err => {
console.log(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
video.remove()
});
} }
video.removeEventListener('play', enterFullscreen); function enterFullscreen(event) {
setTimeout(() => { video.removeEventListener('play', enterFullscreen);
video.style.display = 'block' if (video.webkitRequestFullscreen) {
}, 150) video.requestFullscreen();
} } else {
video.addEventListener('play', enterFullscreen); video.requestFullscreen().catch(err => {
video.addEventListener('fullscreenchange', event => { console.log(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
if (document.fullscreenElement === null) { video.remove()
continueTimecode = video.currentTime video = null
});
}
setTimeout(() => {
video.style.display = 'block'
}, 150)
}
video.addEventListener('play', enterFullscreen);
video.addEventListener('fullscreenchange', event => {
if (document.fullscreenElement === null) {
continueTimecode = video.currentTime
video.remove()
if (document.fullscreenElement) {
document.exitFullscreen();
}
video = null
}
});
video.addEventListener('pause', event => {
})
video.addEventListener('ended', event => {
continueTimecode = 0
video.remove() video.remove()
if (document.fullscreenElement) { if (document.fullscreenElement) {
document.exitFullscreen(); document.exitFullscreen();
} }
} video = null
}); });
video.addEventListener('pause', event => { video.play()
}) }
video.addEventListener('ended', event => {
continueTimecode = 0
video.remove()
if (document.fullscreenElement) {
document.exitFullscreen();
}
});
video.play()
}) })