diff --git a/src/components/frame/Photo.vue b/src/components/frame/Photo.vue index 364fe7ee..509e3a49 100644 --- a/src/components/frame/Photo.vue +++ b/src/components/frame/Photo.vue @@ -269,11 +269,15 @@ export default defineComponent({ }, /** Start preview video */ - playVideo() { + async playVideo() { const video = this.refs.video; - if (video && !(this.data.flag & this.c.FLAG_SELECTED)) { + if (!video || this.data.flag & this.c.FLAG_SELECTED) return; + + try { video.currentTime = 0; - video.play(); + await video.play(); + } catch (e) { + // ignore, pause was probably called too soon } }, diff --git a/src/components/viewer/PsLivePhoto.ts b/src/components/viewer/PsLivePhoto.ts index 76c2b7c3..fc54fe38 100644 --- a/src/components/viewer/PsLivePhoto.ts +++ b/src/components/viewer/PsLivePhoto.ts @@ -27,11 +27,15 @@ class LivePhotoContentSetup { lightbox.on('contentDestroy', this.onContentDestroy.bind(this)); } - play(content: PsContent) { + async play(content: PsContent) { const video = content.element?.querySelector('video'); - if (video) { + if (!video) return; + + try { video.currentTime = 0; - video.play(); + await video.play(); + } catch (e) { + // ignore, pause was probably called too soon } } diff --git a/src/components/viewer/PsVideo.ts b/src/components/viewer/PsVideo.ts index 27e6f27a..19d32a20 100644 --- a/src/components/viewer/PsVideo.ts +++ b/src/components/viewer/PsVideo.ts @@ -222,7 +222,7 @@ class VideoContentSetup { }); // Play the video (hopefully) - const playWithDelay = () => setTimeout(() => content.videojs?.play(), 100); + const playWithDelay = () => setTimeout(() => this.playNoThrow(content.videojs), 100); playWithDelay(); content.videojs.on('canplay', () => { @@ -469,7 +469,15 @@ class VideoContentSetup { const time = vidjs.currentTime(); vidjs.src(src); vidjs.currentTime(time); - vidjs.play(); + this.playNoThrow(vidjs); + } + + async playNoThrow(vidjs: Player | null) { + try { + await vidjs?.play(); + } catch (e) { + // Ignore - video destroyed? + } } onContentDestroy({ content }: PsVideoEvent) {