Skip to content

Commit

Permalink
Setting loudness to default volume in new videos (#3203)
Browse files Browse the repository at this point in the history
* Made changes as suggested.

* Made player set volume to user default if it was muted by dragging volume slider to zero. Volume and muted are kept track of seperately and both are set on player with respect to how it was set for previous video

* added comments

* fixed

* fixed

* Changed comments to be more accurate.
  • Loading branch information
predystopic-dev authored Mar 8, 2023
1 parent 436154b commit 3a904b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/renderer/components/ft-video-player/ft-video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default defineComponent({
id: '',
powerSaveBlocker: null,
volume: 1,
muted: false,
player: null,
useDash: false,
useHls: false,
Expand Down Expand Up @@ -305,11 +306,18 @@ export default defineComponent({
},
mounted: function () {
const volume = sessionStorage.getItem('volume')
const muted = sessionStorage.getItem('muted')

if (volume !== null) {
this.volume = volume
}

if (muted !== null) {
// as sessionStorage stores string values which are truthy by default so we must check with 'true'
// otherwise 'false' will be returned as true as well
this.muted = (muted === 'true')
}

this.dataSetup.playbackRates = this.playbackRates

this.createFullWindowButton()
Expand Down Expand Up @@ -390,6 +398,7 @@ export default defineComponent({
})

this.player.volume(this.volume)
this.player.muted(this.muted)
this.player.playbackRate(this.defaultPlayback)
this.player.textTrackSettings.setValues(this.defaultCaptionSettings)
// Remove big play button
Expand Down Expand Up @@ -699,10 +708,21 @@ export default defineComponent({
},

updateVolume: function (_event) {
// 0 means muted
// https://docs.videojs.com/html5#volume
const volume = this.player.muted() ? 0 : this.player.volume()
sessionStorage.setItem('volume', volume)
if (sessionStorage.getItem('muted') === 'false' && this.player.volume() === 0) {
// If video is muted by dragging volume slider, it doesn't change 'muted' in sessionStorage to true
// hence compare it with 'false' and set volume to defaultVolume.
const volume = parseFloat(sessionStorage.getItem('defaultVolume'))
const muted = true
sessionStorage.setItem('volume', volume)
sessionStorage.setItem('muted', muted)
} else {
// If volume isn't muted by dragging the slider, muted and volume values are carried over to next video.
const volume = this.player.volume()
const muted = this.player.muted()
sessionStorage.setItem('volume', volume)
sessionStorage.setItem('muted', muted)
}
},

mouseScrollVolume: function (event) {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ const stateWithSideEffects = {
defaultValue: 1,
sideEffectsHandler: (_, value) => {
sessionStorage.setItem('volume', value)
value === 0 ? sessionStorage.setItem('muted', 'true') : sessionStorage.setItem('muted', 'false')
sessionStorage.setItem('defaultVolume', value)
}
},

Expand Down

0 comments on commit 3a904b5

Please sign in to comment.