66<template >
77 <!-- Plyr currently replaces the parent. Wrapping to prevent this
88 https://github.com/redxtech/vue-plyr/issues/259 -->
9- <div v-if =" src " >
9+ <div v-if =" url " >
1010 <VuePlyr ref="plyr"
1111 :options =" options "
1212 :style =" {
1717 :autoplay =" active ? true : null"
1818 :playsinline =" true"
1919 :poster =" livePhotoPath"
20- :src =" src "
20+ :src =" url "
2121 preload =" metadata"
22+ @error.capture.prevent.stop.once =" onFail"
2223 @ended =" donePlaying"
2324 @canplay =" doneLoading"
2425 @loadedmetadata =" onLoadedMetadata" >
3536 </div >
3637</template >
3738
38- <script >
39+ <script lang='ts' >
3940// eslint-disable-next-line n/no-missing-import
41+ import Vue from ' vue'
42+ import AsyncComputed from ' vue-async-computed'
4043import ' @skjnldsv/vue-plyr/dist/vue-plyr.css'
44+
4145import { imagePath } from ' @nextcloud/router'
46+
4247import logger from ' ../services/logger.js'
4348import { findLivePhotoPeerFromName } from ' ../utils/livePhotoUtils'
4449import { getPreviewIfAny } from ' ../utils/previewUtils'
50+ import { preloadMedia } from ' ../services/mediaPreloader.js'
4551
4652const VuePlyr = () => import (/* webpackChunkName: 'plyr' */ ' @skjnldsv/vue-plyr' )
4753
4854const blankVideo = imagePath (' viewer' , ' blank.mp4' )
4955
56+ Vue .use (AsyncComputed )
57+
5058export default {
5159 name: ' Videos' ,
5260
@@ -56,6 +64,7 @@ export default {
5664 data() {
5765 return {
5866 isFullscreenButtonVisible: false ,
67+ fallback: false ,
5968 }
6069 },
6170
@@ -86,6 +95,16 @@ export default {
8695 },
8796 },
8897
98+ asyncComputed: {
99+ async url(): Promise <string > {
100+ if (this .fallback ) {
101+ return preloadMedia (this .filename )
102+ } else {
103+ return this .src
104+ }
105+ },
106+ },
107+
89108 watch: {
90109 active(val , old ) {
91110 // the item was hidden before and is now the current view
@@ -155,6 +174,14 @@ export default {
155174 this .player .stop ()
156175 }
157176 },
177+
178+ // Fallback to the original image if not already done
179+ onFail() {
180+ if (! this .fallback ) {
181+ console .error (` Loading of file ${this .filename } failed, falling back to fetching it by hand ` )
182+ this .fallback = true
183+ }
184+ },
158185 },
159186}
160187 </script >
0 commit comments