player: support toggle mute again

This commit is contained in:
Jonas Heinrich 2021-01-20 11:30:30 +01:00
parent f102d87456
commit 1b8fd50d45
2 changed files with 37 additions and 20 deletions

View File

@ -24,15 +24,15 @@
<div id="app-settings">
<div
class="wrap"
:class="{ buffering: player.isBuffering }">
:class="{ buffering: getBuffering }">
<button
class="player"
:class="player.isPlaying ? 'pause' : 'play'"
:class="getPlaying ? 'pause' : 'play'"
@click="togglePlay" />
</div>
<div
class="volumeIcon"
:class="player.volume == 0 ? 'volumeMute' : 'volumeFull'"
:class="getVolume == 0 ? 'volumeMute' : 'volumeFull'"
@click="toggleMute" />
<input
class="volume"
@ -41,31 +41,32 @@
min="0"
max="1"
step=".05"
:value="player.volume"
@input="setVolume($event)">
:value="getVolume"
@input="setVolume($event.target.value)">
<div class="playerMetadata">
{{ player.title }}
{{ getTitle }}
</div>
</div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
export default {
computed: {
player() {
return this.$store.state.player
},
...mapGetters([
'getVolume',
'getBuffering',
'getPlaying',
'getTitle',
]),
},
methods: {
setVolume() {
this.$store.dispatch('setVolume', event.target.value)
},
toggleMute() {
this.$store.dispatch('toggleMute')
},
togglePlay() {
this.$store.dispatch('togglePlay')
},
...mapActions([
'toggleMute',
'setVolume',
'togglePlay',
]),
},
}
</script>

View File

@ -33,6 +33,20 @@ export default ({
oldVolume: localStorage.getItem('radio.volume') || 0.5,
title: '',
},
getters: {
getPlaying: state => {
return state.isPlaying
},
getBuffering: state => {
return state.isBuffering
},
getVolume: state => {
return state.volume
},
getTitle: state => {
return state.title
},
},
mutations: {
setPlaying(state, playerState) {
state.isPlaying = playerState
@ -46,16 +60,18 @@ export default ({
setVolume(state, volume) {
state.volume = volume
localStorage.setItem('radio.volume', volume)
player.setVolume(state.volume)
},
toggleMute(state) {
if (state.isMute) {
state.volume = state.player.oldVolume
state.volume = state.oldVolume
state.isMute = false
} else {
state.oldVolume = state.player.volume
state.oldVolume = state.volume
state.volume = 0
state.isMute = true
}
player.setVolume(state.volume)
},
togglePlay(state) {
if (state.isPlaying) {