Skip to content

Commit

Permalink
Store audio volume in cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
elonen committed Sep 7, 2024
1 parent 033ed5c commit 856b5b3
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions client/src/lib/player_view/VideoPlayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '@fortawesome/fontawesome-free/css/all.min.css';
import * as Proto3 from '@clapshot_protobuf/typescript';
import {VideoFrame} from './VideoFrame';
import {allComments, curSubtitle, videoIsReady, collabId, curVideo} from '@/stores';
import LocalStorageCookies from '@/cookies';
import CommentTimelinePin from './CommentTimelinePin.svelte';
const dispatch = createEventDispatcher();
Expand All @@ -32,6 +32,24 @@ let debug_layout: boolean = false; // Set to true to show CSS layout boxes
let commentsWithTc: Proto3.Comment[] = []; // Will be populated by the store once video is ready (=frame rate is known)
let animationFrameId: number = 0;
let audio_volume: number;
function initializeVolume() {
const storedVolume = LocalStorageCookies.get('audio_volume');
audio_volume = storedVolume ? parseInt(storedVolume) : 100;
if (videoElem) {
videoElem.volume = audio_volume / 100;
}
}
$: {
if (videoElem) {
videoElem.volume = audio_volume / 100;
LocalStorageCookies.set('audio_volume', audio_volume.toString(), null);
}
}
function refreshCommentPins(): void {
// Make pins for all comments with timecode
Expand Down Expand Up @@ -119,6 +137,7 @@ onMount(async () => {
allComments.subscribe((_v) => { refreshCommentPins(); });
curSubtitle.subscribe(() => { offsetTextTracks(); });
animationFrameId = requestAnimationFrame(handleTimeUpdate);
initializeVolume();
});
onDestroy(async () => {
Expand Down Expand Up @@ -319,12 +338,6 @@ export function seekToFrame(frame: number) {
}
}
// Audio control
let audio_volume = 50;
$:{
if (videoElem)
videoElem.volume = audio_volume/100; // Immediately changes video element volume
}
// These are called from PARENT component on user interaction
export function onToggleDraw(mode_on: boolean) {
Expand Down

0 comments on commit 856b5b3

Please sign in to comment.