Skip to content

Commit

Permalink
🐛 Limit volume to a value between 0-1 (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
patricgruber authored Jul 12, 2024
1 parent 9a97e4f commit d7f8a32
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions client/app/composables/videoplayer/videoState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ export const useVideoState = ({
};
const stop = () => adapterInstance.value?.stop();
const setVolume = (volume: number) => {
volumeStorage.value = volume;
adapterInstance.value?.setVolume(volume);
const clampedVolume = clamp(volume, 0, 1);
volumeStorage.value = clampedVolume;
adapterInstance.value?.setVolume(clampedVolume);
};
const setMuted = (muted: boolean) => (videoElementRef.value.muted = muted);
const setPlaybackRate = (playbackRate: number) =>
Expand Down Expand Up @@ -169,7 +170,7 @@ export const useVideoState = ({
lengthSeconds: videoState.duration
},
credentials: 'include'
}).catch(_ => {});
}).catch(_ => { });
}
};

Expand Down Expand Up @@ -203,6 +204,16 @@ export const useVideoState = ({

useMediaSession({ video, videoState, play, pause, stop, setTime, onNextTrack });

function clamp(value: number, min: number, max: number): number {
if (value < min) {
return min;
}
if (value > max) {
return max;
}
return value;
}

return {
video: videoState,
play,
Expand Down

0 comments on commit d7f8a32

Please sign in to comment.