koel/resources/assets/js/components/ui/Volume.vue

97 lines
1.8 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<span id="volume" class="volume control">
2022-04-15 14:24:30 +00:00
<i
v-if="muted"
2022-04-15 14:24:30 +00:00
class="fa fa-volume-off unmute"
role="button"
tabindex="0"
title="Unmute"
@click="unmute"
2022-04-15 14:24:30 +00:00
></i>
<i
v-else
2022-04-15 14:24:30 +00:00
class="fa fa-volume-up mute"
role="button"
tabindex="0"
title="Mute"
@click="mute"
2022-04-15 14:24:30 +00:00
></i>
<input
id="volumeRange"
class="plyr__volume"
2022-04-15 14:24:30 +00:00
max="10"
step="0.1"
title="Volume"
type="range"
@change="broadcastVolume"
@input="setVolume"
2022-04-15 14:24:30 +00:00
>
</span>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { ref } from 'vue'
2022-04-24 08:50:45 +00:00
import { playbackService, socketService } from '@/services'
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const muted = ref(false)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const mute = () => {
muted.value = true
2022-04-24 08:50:45 +00:00
playbackService.mute()
2022-04-15 17:00:08 +00:00
}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const unmute = () => {
muted.value = false
2022-04-24 08:50:45 +00:00
playbackService.unmute()
2022-04-15 17:00:08 +00:00
}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const setVolume = (e: InputEvent) => {
const volume = parseFloat((e.target as HTMLInputElement).value)
2022-04-24 08:50:45 +00:00
playbackService.setVolume(volume)
2022-04-15 17:00:08 +00:00
muted.value = volume === 0
}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
/**
* Broadcast the volume changed event to remote controller.
*/
const broadcastVolume = (e: InputEvent) => {
2022-04-24 08:50:45 +00:00
socketService.broadcast('SOCKET_VOLUME_CHANGED', parseFloat((e.target as HTMLInputElement).value))
2022-04-15 17:00:08 +00:00
}
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss">
#volume {
position: relative;
z-index: 99;
// More tweaks
[type=range] {
margin: -1px 0 0 5px;
transform: rotate(270deg);
transform-origin: 0;
position: absolute;
bottom: -25px;
border: 14px solid var(--color-bg-primary);
border-left-width: 30px;
z-index: 0;
width: 140px;
border-radius: 4px;
display: none;
}
&:hover [type=range] {
display: block;
}
i {
width: 16px;
position: relative;
z-index: 1;
}
@media only screen and (max-width: 768px) {
display: none !important;
}
}
</style>