From d1c532c2fbbe48ffcee67a4c283634034d827ad2 Mon Sep 17 00:00:00 2001 From: SimplyBoo Date: Sun, 4 Jul 2021 08:58:46 +0100 Subject: [PATCH] Preload video preview when using video player --- .../components/preview/preview.component.html | 6 +-- .../components/preview/preview.component.ts | 41 +++++++++++-------- .../video-player/video-player.component.html | 8 +++- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/client/src/app/components/preview/preview.component.html b/client/src/app/components/preview/preview.component.html index e21f2a5..50a496b 100755 --- a/client/src/app/components/preview/preview.component.html +++ b/client/src/app/components/preview/preview.component.html @@ -1,8 +1,8 @@ this.media.metadata.length) { this.index = 0; } - if (this.image) { + if (this.preview) { this.rendered = false; this.render(); } @@ -151,20 +158,20 @@ export class PreviewComponent implements OnInit, OnDestroy, OnChanges { public ngOnChanges(changes: SimpleChanges) { if (changes.media && changes.media.currentValue) { const media = changes.media.currentValue; - this.image = undefined; + this.preview = undefined; this.thumbnail = undefined; this.index = undefined; this.rendered = false; if (media.metadata) { if (media.type === 'video' && media.preview) { - this.imageSrc = `/cache/previews/${media.hash}.png`; + this.previewSrc = `/cache/previews/${media.hash}.png`; } this.thumbnailSrc = `/cache/thumbnails/${media.hash}.png`; } } if (changes.offset && this.config) { - this.imageRequested = true; + this.previewRequested = true; const index = Math.floor( (changes.offset.currentValue || 0) / this.config.transcoder.videoPreviewFps, @@ -184,7 +191,7 @@ export class PreviewComponent implements OnInit, OnDestroy, OnChanges { } // If nothing to render, leave early - if (!this.image && !this.thumbnail) { + if (!this.preview && !this.thumbnail) { return; } @@ -218,13 +225,13 @@ export class PreviewComponent implements OnInit, OnDestroy, OnChanges { ); } } else { - if (this.image) { + if (this.preview) { const mediaHeight = this.config.transcoder.videoPreviewHeight; const mediaWidth = Math.ceil( (this.media.metadata.width / this.media.metadata.height) * mediaHeight, ); - const columns = Math.ceil(this.image.naturalWidth / mediaWidth); + const columns = Math.ceil(this.preview.naturalWidth / mediaWidth); const column = this.index % columns; const row = (this.index - column) / columns; @@ -233,7 +240,7 @@ export class PreviewComponent implements OnInit, OnDestroy, OnChanges { const offsetY = row * mediaHeight; canvas.drawImage( - this.image, + this.preview, offsetX, offsetY, mediaWidth, @@ -247,9 +254,9 @@ export class PreviewComponent implements OnInit, OnDestroy, OnChanges { } } - public onImageLoaded(event: any) { - console.log('Preview loaded', this.imageSrc); - this.image = event.target; + public onPreviewLoaded(event: any) { + console.log('Preview loaded', this.previewSrc); + this.preview = event.target; this.changeDetector.detectChanges(); this.rendered = false; this.render(); diff --git a/client/src/app/components/video-player/video-player.component.html b/client/src/app/components/video-player/video-player.component.html index cbd2697..855e0bf 100755 --- a/client/src/app/components/video-player/video-player.component.html +++ b/client/src/app/components/video-player/video-player.component.html @@ -17,7 +17,12 @@ [style.height.px]="videoPlayerState.height" [style.top.px]="videoPlayerState.top" > - + @@ -81,6 +86,7 @@ videoPlayerState.duration !== undefined " class="preview" + [preloadPreview]="true" [media]="media" [offset]="videoPlayerState.previewTime" [style.left.px]="