-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use vue-3-slider-component for all slider range inputs - Now you can drag-and-drop the dot to seek in the seek bar and volume control bar
- Loading branch information
1 parent
852ad12
commit f9c7215
Showing
9 changed files
with
139 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,72 @@ | ||
<template> | ||
<div class="bg-brave-90 w-full h-2 relative origin-center hover:scale-y-150 transition" @mouseover="onMouseOver" @mousemove="onMouseOver" @mouseleave="onMouseLeave" @click="chooseProgress"> | ||
<div class="bg-brave-30 h-full" :style="{ width: progressPercent }"></div> | ||
<div class="bg-brave-60 h-full absolute top-0 left-0 opacity-40" :style="{ width: choosingProgressPercent }"></div> | ||
</div> | ||
<VueSlider | ||
v-model="progressPercent" | ||
:min="0" | ||
:max="1" | ||
:interval="0.001" | ||
:duration="0" | ||
:rail-style="{ backgroundColor: '#ffd9e2' }" | ||
:dot-style="{ transition: 'initial' }" | ||
:tooltip-style="{ zIndex: 200 }" | ||
tooltip="hover" | ||
@change="chooseProgress" | ||
> | ||
<template #dot="{pos, index, value, focus, disabled}"> | ||
<div | ||
class="w-full h-full rounded-full bg-brave-30" | ||
/> | ||
</template> | ||
|
||
<template #process="{ start, end }"> | ||
<div | ||
class="absolute h-full rounded-full bg-brave-30" | ||
:style="'width: ' + end + '%;'" | ||
/> | ||
</template> | ||
|
||
<template #tooltip="{pos, index, value, focus, disabled}"> | ||
<div v-if="value" class="text-brave-30 text-[0.6rem] font-bold rounded-lg px-1 py-0.5 bg-brave-90">{{ humanDuration(value * props.duration) }}</div> | ||
</template> | ||
</VueSlider> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, computed, onMounted } from 'vue' | ||
import VueSlider from "vue-3-slider-component"; | ||
import { ref, onMounted, watch } from 'vue' | ||
import { humanDuration } from '@/utils/human-duration' | ||
import _throttle from 'lodash/throttle' | ||
const props = defineProps(['duration', 'progress']) | ||
const emit = defineEmits(['seek']) | ||
const isGracePeriod = ref(false) | ||
const gracePeriodTimeout = ref(null) | ||
const progressPercent = computed(() => { | ||
if (!props.progress || !props.duration) { | ||
return '0%' | ||
} | ||
return `${(props.progress / props.duration) * 100}%` | ||
}) | ||
const progressPercent = ref(0) | ||
const choosingProgress = ref(0.0) | ||
// There is a slight delay after seeking before the player can actually start playing from the new position due to kira's StreamingSoundHandle. | ||
// So this is a hack to prevent the seek bar from jumping back to the old position after user seeks. | ||
// Also throttle the seek event to prevent it from being called too frequently. | ||
const chooseProgress = _throttle((value) => { | ||
emit('seek', value * props.duration) | ||
const choosingProgressPercent = computed(() => `${choosingProgress.value * 100}%` ) | ||
isGracePeriod.value = true | ||
const onMouseOver = (event) => { | ||
const totalWidth = event.currentTarget.clientWidth | ||
const seekWidth = event.offsetX | ||
choosingProgress.value = seekWidth / totalWidth | ||
} | ||
clearTimeout(gracePeriodTimeout.value) | ||
gracePeriodTimeout.value = setTimeout(() => { | ||
isGracePeriod.value = false | ||
}, 500) | ||
}, 200) | ||
const onMouseLeave = (event) => { | ||
choosingProgress.value = 0.0 | ||
} | ||
onMounted(() => { | ||
progressPercent.value = props.progress / props.duration | ||
}) | ||
const chooseProgress = () => { | ||
emit('seek', choosingProgress.value * props.duration) | ||
} | ||
watch(() => props.progress, (newProgress) => { | ||
if (isGracePeriod.value) return | ||
progressPercent.value = newProgress / props.duration | ||
}) | ||
watch(() => props.duration, (newDuration) => { | ||
progressPercent.value = props.progress / newDuration | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,63 @@ | ||
<template> | ||
<div class="flex items-center gap-1"> | ||
<button v-if="volume > 0" @click="mute" class="button text-brave-30 p-1 m-1 rounded-full"><VolumeMedium /></button> | ||
<button v-else @click="unmute" class="button text-brave-30 p-1 m-1 rounded-full"><VolumeMute /></button> | ||
|
||
<div class="bg-brave-90 w-32 h-2 relative origin-center hover:scale-y-150 transition" @mouseover="onMouseOver" @mousemove="onMouseOver" @mouseleave="onMouseLeave" @click="chooseVolume"> | ||
<div class="bg-brave-30 h-full" :style="{ width: volumePercent }"></div> | ||
<div class="bg-brave-60 h-full absolute top-0 left-0 opacity-40" :style="{ width: choosingVolumePercent }"></div> | ||
</div> | ||
<div class="flex items-center gap-1 w-40"> | ||
<button v-if="volume > 0" @click="mute" class="flex-none button text-brave-30 p-1 m-1 rounded-full"><VolumeMedium /></button> | ||
<button v-else @click="unmute" class="flex-none button text-brave-30 p-1 m-1 rounded-full"><VolumeMute /></button> | ||
|
||
<VueSlider | ||
class="grow" | ||
v-model="volume" | ||
:min="0" | ||
:max="1" | ||
:interval="0.01" | ||
:rail-style="{ backgroundColor: '#ffd9e2' }" | ||
tooltip="hover" | ||
@change="chooseVolume" | ||
> | ||
<template #dot="{pos, index, value, focus, disabled}"> | ||
<div | ||
class="w-full h-full rounded-full bg-brave-30" | ||
/> | ||
</template> | ||
|
||
<template #process="{ start, end }"> | ||
<div | ||
class="absolute h-full rounded-full bg-brave-30" | ||
:style="'width: ' + end + '%;'" | ||
/> | ||
</template> | ||
|
||
<template #tooltip="{pos, index, value, focus, disabled}"> | ||
<div v-if="value && value > 0" class="text-brave-30 text-[0.6rem] font-bold rounded-lg px-1 py-0.5 bg-brave-90">{{ Math.round(value * 100) }}%</div> | ||
</template> | ||
</VueSlider> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { VolumeMedium, VolumeMute } from 'mdue'; | ||
import { ref, computed } from 'vue' | ||
import VueSlider from "vue-3-slider-component"; | ||
import { ref, watch } from 'vue' | ||
const props = defineProps(['volume']) | ||
const emit = defineEmits(['setVolume']) | ||
const volumePercent = computed(() => `${props.volume * 100}%`) | ||
const volume = ref(props.volume) | ||
const choosingVolume = ref(0.0) | ||
const choosingVolumePercent = computed(() => `${choosingVolume.value * 100}%`) | ||
const onMouseOver = (event) => { | ||
const totalWidth = event.currentTarget.clientWidth | ||
const seekWidth = event.offsetX | ||
choosingVolume.value = seekWidth / totalWidth | ||
} | ||
const onMouseLeave = () => { | ||
choosingVolume.value = 0.0 | ||
} | ||
const chooseVolume = () => { | ||
emit('setVolume', choosingVolume.value) | ||
const chooseVolume = (value) => { | ||
emit('setVolume', value) | ||
} | ||
const mute = () => { | ||
volume.value = 0.0 | ||
emit('setVolume', 0.0) | ||
} | ||
const unmute = () => { | ||
volume.value = 1.0 | ||
emit('setVolume', 1.0) | ||
} | ||
watch(props.volume, (newVolume) => { | ||
volume.value = newVolume | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters