diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-03-15 19:09:37 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-03-15 19:09:37 +0100 |
| commit | 8792e9fe1c7ab76c35f9a18d866880ba3da2c13e (patch) | |
| tree | fbdc78484f654ec344d10814cb83987c873d4360 /frontend/app/utils/index.js | |
| parent | 7c15f34186622410e25ee85c01d832e48e012140 (diff) | |
move frontend site folder. add video support
Diffstat (limited to 'frontend/app/utils/index.js')
| -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 bb5e01d..ce8d75c 100644 --- a/frontend/app/utils/index.js +++ b/frontend/app/utils/index.js @@ -120,6 +120,35 @@ export const preloadImage = url => ( }) ) +export const preloadVideo = url => ( + new Promise((resolve, reject) => { + const video = document.createElement('video') + let loaded = false + const bind = () => { + video.addEventListener('loadedmetadata', onload) + video.addEventListener('error', onerror) + } + const unbind = () => { + video.removeEventListener('loadedmetadata', onload) + video.removeEventListener('error', onerror) + } + const onload = () => { + if (loaded) return + loaded = true + unbind() + resolve(video) + } + const onerror = (error) => { + if (loaded) return + loaded = true + unbind() + reject(error) + } + bind() + video.src = url + }) +) + export const cropImage = (url, crop) => { return new Promise((resolve, reject) => { let { x, y, w, h } = crop |
