trying to implement volume toggle

This commit is contained in:
Jonas Heinrich 2020-10-25 10:51:08 +01:00
parent a3835f4e3e
commit 775c6aebf4
2 changed files with 19 additions and 1 deletions

View File

@ -9,7 +9,8 @@
</div> </div>
<div <div
class="volumeIcon" class="volumeIcon"
:class="player.volume == 0 ? 'volumeMute' : 'volumeVolume'" /> :class="player.volume == 0 ? 'volumeMute' : 'volumeVolume'"
@click="toggleMute" />
<input <input
class="volume" class="volume"
type="range" type="range"
@ -34,6 +35,9 @@ export default {
changeVolume() { changeVolume() {
this.$store.dispatch('changeVolume', event.target.value) this.$store.dispatch('changeVolume', event.target.value)
}, },
toggleMute() {
this.$store.dispatch('toggleMute')
},
}, },
} }
</script> </script>
@ -98,6 +102,7 @@ export default {
position: relative; position: relative;
left: 85px; left: 85px;
top: 20px; top: 20px;
cursor: pointer;
} }
.volumeFull { .volumeFull {

View File

@ -8,6 +8,8 @@ export default new Vuex.Store({
isPlaying: false, isPlaying: false,
isBuffering: false, isBuffering: false,
volume: 0, volume: 0,
isMute: false,
oldVolume: 0,
}, },
}, },
mutations: { mutations: {
@ -20,6 +22,14 @@ export default new Vuex.Store({
changeVolume(state, volume) { changeVolume(state, volume) {
state.player.volume = volume state.player.volume = volume
}, },
toggleMute(state) {
if (state.player.isMute) {
state.player.volume = state.player.oldVolume
} else {
state.player.oldVolume = state.player.volume
state.player.volume = 0
}
},
}, },
actions: { actions: {
isPlaying(context, playerState) { isPlaying(context, playerState) {
@ -31,5 +41,8 @@ export default new Vuex.Store({
changeVolume(context, volume) { changeVolume(context, volume) {
context.commit('changeVolume', volume) context.commit('changeVolume', volume)
}, },
toggleMute(context) {
context.toggleMute()
},
}, },
}) })