From 564fb7a11ea5d66c707288717ead6b59a00c25ec Mon Sep 17 00:00:00 2001 From: Ochieng Paul Date: Fri, 19 Apr 2024 17:46:57 +0300 Subject: [PATCH] Refactor video player component to include progress bar and update video player service --- .../src/features/video-player/video-player.component.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/shared/src/features/video-player/video-player.component.ts b/libs/shared/src/features/video-player/video-player.component.ts index 53f35bf24..37ea386aa 100644 --- a/libs/shared/src/features/video-player/video-player.component.ts +++ b/libs/shared/src/features/video-player/video-player.component.ts @@ -67,6 +67,8 @@ export class VideoPlayerComponent implements OnDestroy { private pauseTime = 0; + totalTime: number; + playbackPercentage: number; constructor( @@ -99,16 +101,16 @@ export class VideoPlayerComponent implements OnDestroy { private async saveVideoState() { // Getting the total time of the video const totalTimeResult = await this.videoPlayer.getDuration({ playerId: this.playerId }); - const totalTime = totalTimeResult.value; + this.totalTime = totalTimeResult.value || this.totalTime; // Calculating the playback percentage - this.playbackPercentage = (this.pauseTime / totalTime) * 100; + this.playbackPercentage = (this.pauseTime / this.totalTime) * 100; // Saving the video state const videoState = { videoId: this.playerId, currentTime: this.pauseTime || 0, - totalTime: totalTime || 0, + totalTime: this.totalTime || 0, playbackPercentage: this.playbackPercentage || 0, }; await this.playerService.updateVideoState(videoState);