diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-04-28 23:15:53 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-04-28 23:15:53 +0200 |
| commit | 51288f81110850e346e6303115a0780b3d4668b4 (patch) | |
| tree | 1337a298ea2941df22aecffe628fad29cd97aed9 /frontend/app/utils | |
| parent | 938545387a234b2cd34bd5f52e0efe5fdd1b71c0 (diff) | |
preloading...
Diffstat (limited to 'frontend/app/utils')
| -rw-r--r-- | frontend/app/utils/index.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/frontend/app/utils/index.js b/frontend/app/utils/index.js index b8a2ed7..e2072b6 100644 --- a/frontend/app/utils/index.js +++ b/frontend/app/utils/index.js @@ -181,6 +181,35 @@ export const preloadVideo = url => ( }) ) +export const preloadAudio = url => ( + new Promise((resolve, reject) => { + const audio = document.createElement('audio') + let loaded = false + const bind = () => { + audio.addEventListener('loadedmetadata', onload) + audio.addEventListener('error', onerror) + } + const unbind = () => { + audio.removeEventListener('loadedmetadata', onload) + audio.removeEventListener('error', onerror) + } + const onload = () => { + if (loaded) return + loaded = true + unbind() + resolve(audio) + } + const onerror = (error) => { + if (loaded) return + loaded = true + unbind() + reject(error) + } + bind() + audio.src = url + }) +) + export const cropImage = (url, crop) => { return new Promise((resolve, reject) => { let { x, y, w, h } = crop |
