set and get playerVolume from localStorage

This commit is contained in:
Simon 2023-11-09 09:31:19 +07:00
parent 1188e66f37
commit 6bc0111d0a
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 9 additions and 1 deletions

View File

@ -546,7 +546,7 @@ function createVideoTag(videoData, videoProgress) {
}
let videoTag = `
<video poster="${videoThumbUrl}" ontimeupdate="onVideoProgress()" onpause="onVideoPause()" onended="onVideoEnded()" controls autoplay width="100%" playsinline id="video-item">
<video poster="${videoThumbUrl}" onvolumechange="onVolumeChange(this)" onloadstart="this.volume=getPlayerVolume()" ontimeupdate="onVideoProgress()" onpause="onVideoPause()" onended="onVideoEnded()" controls autoplay width="100%" playsinline id="video-item">
<source src="${videoUrl}#t=${videoProgress}" type="video/mp4" id="video-source" videoid="${videoId}">
${subtitles}
</video>
@ -554,6 +554,14 @@ function createVideoTag(videoData, videoProgress) {
return videoTag;
}
function onVolumeChange(videoTag) {
localStorage.setItem('playerVolume', videoTag.volume);
}
function getPlayerVolume() {
return localStorage.getItem('playerVolume') ?? 1;
}
// Gets video tag
function getVideoPlayer() {
let videoElement = document.getElementById('video-item');