diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-04-29 14:53:57 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-04-29 14:53:57 +0200 |
| commit | d31a4ae6d634ac86325ccbe424110525c14a5589 (patch) | |
| tree | 3c07f264649ce74747327d8e35c1d61dd1d6e0b1 /frontend/app/utils | |
| parent | 51288f81110850e346e6303115a0780b3d4668b4 (diff) | |
final fixes?
Diffstat (limited to 'frontend/app/utils')
| -rw-r--r-- | frontend/app/utils/index.js | 8 |
1 files changed, 5 insertions, 3 deletions
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 }) ) |
