Add fallback image for video loading and error states

This commit is contained in:
Chneemann 2024-09-11 04:56:45 +02:00
parent d4625cd5e8
commit 16a6e351d4
2 changed files with 26 additions and 0 deletions

View file

@ -9,6 +9,19 @@
fullVhBanner: !screenWidth fullVhBanner: !screenWidth
}" }"
> >
<!-- Fallback image is displayed before the video is loaded -->
<img
*ngIf="!isVideoLoaded"
[src]="
environmentBaseUrl +
'/media/thumbnails/' +
currentMovie[0]?.id +
'/' +
currentMovie[0]?.file_name +
'_1080p.jpg'
"
class="fallback-image"
/>
<video <video
#videoElement #videoElement
*ngIf="currentMovie[0]?.file_name" *ngIf="currentMovie[0]?.file_name"
@ -25,6 +38,8 @@
loop loop
playsinline playsinline
class="video-banner" class="video-banner"
(canplay)="onVideoLoad()"
(error)="onVideoError()"
> >
<img <img
[src]=" [src]="
@ -35,9 +50,11 @@
currentMovie[0]?.file_name + currentMovie[0]?.file_name +
'_1080p.jpg' '_1080p.jpg'
" "
alt="Fallback image"
/> />
</video> </video>
</div> </div>
@if (currentMovie.length > 0) { @if (currentMovie.length > 0) {
<div <div
class="content" class="content"

View file

@ -35,6 +35,7 @@ export class HeroBannerComponent implements OnChanges {
@Output() moviesChange = new EventEmitter<any[]>(); @Output() moviesChange = new EventEmitter<any[]>();
@Output() favoriteMovieChange = new EventEmitter<any[]>(); @Output() favoriteMovieChange = new EventEmitter<any[]>();
isVideoLoaded: boolean = false;
environmentBaseUrl: string = environment.baseUrl; environmentBaseUrl: string = environment.baseUrl;
movieIsUploaded: { [resolution: string]: boolean } = { movieIsUploaded: { [resolution: string]: boolean } = {
'320': true, '320': true,
@ -50,6 +51,14 @@ export class HeroBannerComponent implements OnChanges {
this.videoSpeed(); this.videoSpeed();
} }
onVideoLoad() {
this.isVideoLoaded = true;
}
onVideoError() {
this.isVideoLoaded = false;
}
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if (changes['currentMovie'] && this.currentMovie.length > 0) { if (changes['currentMovie'] && this.currentMovie.length > 0) {
const movieId = this.currentMovie[0]?.id; const movieId = this.currentMovie[0]?.id;