From d31a4ae6d634ac86325ccbe424110525c14a5589 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 29 Apr 2021 14:53:57 +0200 Subject: final fixes? --- frontend/app/utils/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'frontend/app/utils/index.js') diff --git a/frontend/app/utils/index.js b/frontend/app/utils/index.js index e2072b6..400637e 100644 --- a/frontend/app/utils/index.js +++ b/frontend/app/utils/index.js @@ -152,16 +152,16 @@ export const preloadImage = url => ( }) ) -export const preloadVideo = url => ( +export const preloadVideo = (url, { canplaythrough }) => ( new Promise((resolve, reject) => { const video = document.createElement('video') let loaded = false const bind = () => { - video.addEventListener('loadedmetadata', onload) + video.addEventListener(canplaythrough ? 'canplaythrough' : 'loadedmetadata', onload) video.addEventListener('error', onerror) } const unbind = () => { - video.removeEventListener('loadedmetadata', onload) + video.removeEventListener(canplaythrough ? 'canplaythrough' : 'loadedmetadata', onload) video.removeEventListener('error', onerror) } const onload = () => { @@ -177,6 +177,7 @@ export const preloadVideo = url => ( reject(error) } bind() + video.preload = 'auto' video.src = url }) ) @@ -206,6 +207,7 @@ export const preloadAudio = url => ( reject(error) } bind() + audio.preload = 'auto' audio.src = url }) ) -- cgit v1.2.3-70-g09d2