fix(playback): previous button now seeks to 0 when track is listened over 3 seconds

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2305>
This commit is contained in:
wvffle 2022-12-27 13:09:12 +00:00
parent a48f1b5449
commit 1b6de47a4f
2 changed files with 13 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import { computed } from 'vue'
import { usePlayer } from '~/composables/audio/player' import { usePlayer } from '~/composables/audio/player'
import { useQueue } from '~/composables/audio/queue' import { useQueue } from '~/composables/audio/queue'
const { hasPrevious, playPrevious, hasNext, playNext, currentTrack } = useQueue() const { playPrevious, hasNext, playNext, currentTrack } = useQueue()
const { isPlaying } = usePlayer() const { isPlaying } = usePlayer()
const { t } = useI18n() const { t } = useI18n()
@ -22,11 +22,10 @@ const labels = computed(() => ({
<button <button
:title="labels.previous" :title="labels.previous"
:aria-label="labels.previous" :aria-label="labels.previous"
:disabled="!hasPrevious"
class="circular button control tablet-and-up" class="circular button control tablet-and-up"
@click.prevent.stop="playPrevious()" @click.prevent.stop="playPrevious()"
> >
<i :class="['ui', 'large', {'disabled': !hasPrevious}, 'backward step', 'icon']" /> <i :class="['ui', 'large', 'backward step', 'icon']" />
</button> </button>
<button <button
v-if="!isPlaying" v-if="!isPlaying"

View File

@ -6,7 +6,7 @@ import { shuffle as shuffleArray, sum } from 'lodash-es'
import { useClamp } from '@vueuse/math' import { useClamp } from '@vueuse/math'
import { useStore } from '~/store' import { useStore } from '~/store'
import { looping, LoopingMode, isPlaying } from '~/composables/audio/player' import { looping, LoopingMode, isPlaying, usePlayer } from '~/composables/audio/player'
import { delMany, getMany, setMany } from '~/composables/data/indexedDB' import { delMany, getMany, setMany } from '~/composables/data/indexedDB'
import { setGain } from '~/composables/audio/audio-api' import { setGain } from '~/composables/audio/audio-api'
import { useTracks } from '~/composables/audio/tracks' import { useTracks } from '~/composables/audio/tracks'
@ -199,8 +199,13 @@ export const useQueue = createGlobalState(() => {
} }
// Previous track // Previous track
const hasPrevious = computed(() => looping.value === LoopingMode.LoopQueue || currentIndex.value !== 0)
const playPrevious = async (force = false) => { const playPrevious = async (force = false) => {
// If we're only 3 seconds into track, we seek to the beginning
const { currentTime } = usePlayer()
if (currentTime.value >= 3) {
return playTrack(currentIndex.value, true)
}
// Loop entire queue / change track to the next one // Loop entire queue / change track to the next one
if (looping.value === LoopingMode.LoopQueue && currentIndex.value === 0 && force !== true) { if (looping.value === LoopingMode.LoopQueue && currentIndex.value === 0 && force !== true) {
// Loop track programmatically if it is the only track in the queue // Loop track programmatically if it is the only track in the queue
@ -208,6 +213,10 @@ export const useQueue = createGlobalState(() => {
return playTrack(tracks.value.length - 1) return playTrack(tracks.value.length - 1)
} }
if (currentIndex.value === 0) {
return playTrack(currentIndex.value, true)
}
return playTrack(currentIndex.value - 1) return playTrack(currentIndex.value - 1)
} }
@ -369,7 +378,6 @@ export const useQueue = createGlobalState(() => {
currentIndex, currentIndex,
currentTrack, currentTrack,
playTrack, playTrack,
hasPrevious,
hasNext, hasNext,
playPrevious, playPrevious,
playNext, playNext,