video: catch play throws

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/900/head
Varun Patil 2023-10-30 01:21:06 -07:00
parent 37783d831d
commit 1e5a5d3b4f
3 changed files with 24 additions and 8 deletions

View File

@ -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
}
},

View File

@ -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
}
}

View File

@ -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) {