Skip to content

Commit

Permalink
Refactor video player component to include progress bar and update vi…
Browse files Browse the repository at this point in the history
…deo player service
  • Loading branch information
OchiengPaul442 committed Apr 19, 2024
1 parent af50524 commit d2237d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,5 @@ $icon-size: 3rem;
.progress-bar {
position: relative;
width: 100%;
height: auto;
background-color: rgba(0, 0, 0, 0.25);
z-index: 99;
}
32 changes: 16 additions & 16 deletions libs/shared/src/features/video-player/video-player.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,18 @@ export class VideoPlayerComponent implements OnDestroy {
private playerService: VideoPlayerService
) {}

// async ngOnInit() {
// await this.loadVideoState();
// }

// private async loadVideoState() {
// const videoState = await this.playerService.getVideoState(this.playerId);
// if (videoState) {
// this.pauseTime = videoState.currentTime;
// this.playbackPercentage = videoState.playbackPercentage;
// }
// }
async ngOnInit() {
await this.loadVideoState();
}

private async loadVideoState() {
await this.playerService.init();
const videoState = await this.playerService.getVideoState(this.playerId);
if (videoState) {
this.pauseTime = videoState.currentTime;
this.playbackPercentage = videoState.playbackPercentage;
}
}

async ngOnDestroy() {
await this.videoPlayer.stopAllPlayers();
Expand All @@ -96,22 +97,21 @@ export class VideoPlayerComponent implements OnDestroy {
}

private async saveVideoState() {
// Get the total time of the video
// Getting the total time of the video
const totalTimeResult = await this.videoPlayer.getDuration({ playerId: this.playerId });
const totalTime = totalTimeResult.value;

// Calculate the playback percentage
// Calculating the playback percentage
this.playbackPercentage = (this.pauseTime / totalTime) * 100;

// Save the video state
// Saving the video state
const videoState = {
videoId: this.playerId,
currentTime: this.pauseTime || 0,
totalTime: totalTime || 0,
playbackPercentage: this.playbackPercentage || 0,
};
console.log('Video State:', videoState);
// await this.playerService.updateVideoState(videoState);
await this.playerService.updateVideoState(videoState);
}

public async pauseVideo() {
Expand Down
5 changes: 4 additions & 1 deletion libs/shared/src/services/video-player.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Injectable } from '@angular/core';
import { RxCollection } from 'rxdb';
import { addRxPlugin, RxCollection } from 'rxdb';
import { RxDBUpdatePlugin } from 'rxdb/plugins/update';

import { IVideoPlayback, videoPlayback } from '../features/video-player/schema/schema';
import { PicsaAsyncService } from './asyncService.service';
import { PicsaDatabase_V2_Service } from './core/db_v2';

addRxPlugin(RxDBUpdatePlugin);

@Injectable({
providedIn: 'root',
})
Expand Down

0 comments on commit d2237d7

Please sign in to comment.