2022-10-26 12:34:32 +00:00
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
<div
|
|
|
|
:style="{ backgroundImage: `url(${defaultCover})` }"
|
|
|
|
class="song-thumbnail group w-[48px] min-w-[48px] aspect-square bg-cover relative rounded overflow-hidden flex
|
|
|
|
items-center justify-center
|
|
|
|
before:absolute before:w-full before:h-full before:pointer-events-none before:z-[1]
|
|
|
|
before:left-0 before:top-0 before:bg-black before:opacity-0 hover:before:opacity-70"
|
|
|
|
>
|
2024-02-24 15:37:01 +00:00
|
|
|
<img
|
|
|
|
v-koel-hide-broken-icon
|
|
|
|
:alt="song.album_name"
|
|
|
|
:src="song.album_cover"
|
2024-04-04 22:20:42 +00:00
|
|
|
class="w-full h-full object-cover absolute left-0 top-0 pointer-events-none"
|
2024-02-24 15:37:01 +00:00
|
|
|
loading="lazy"
|
|
|
|
>
|
2024-04-04 22:20:42 +00:00
|
|
|
<a
|
|
|
|
:title="title"
|
|
|
|
class="w-7 h-7 text-base z-[1] text-k-text-primary duration-300 justify-center
|
|
|
|
items-center rounded-full bg-black/50 pl-0.5 flex opacity-0 group-hover:opacity-100"
|
|
|
|
role="button"
|
|
|
|
@click.prevent="changeSongState"
|
|
|
|
>
|
|
|
|
<Icon :icon="song.playback_state === 'Playing' ? faPause : faPlay" class="text-k-highlight" />
|
2022-10-26 12:34:32 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-11-29 10:18:58 +00:00
|
|
|
import { computed, toRefs } from 'vue'
|
2022-10-26 12:34:32 +00:00
|
|
|
import { faPause, faPlay } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { defaultCover } from '@/utils'
|
|
|
|
import { playbackService } from '@/services'
|
|
|
|
import { queueStore } from '@/stores'
|
|
|
|
|
|
|
|
const props = defineProps<{ song: Song }>()
|
|
|
|
const { song } = toRefs(props)
|
|
|
|
|
|
|
|
const play = () => {
|
|
|
|
queueStore.queueIfNotQueued(song.value)
|
|
|
|
playbackService.play(song.value)
|
|
|
|
}
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
const title = computed(() => {
|
|
|
|
if (song.value.playback_state === 'Playing') {
|
|
|
|
return 'Pause'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (song.value.playback_state === 'Paused') {
|
|
|
|
return 'Resume'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Play'
|
|
|
|
})
|
|
|
|
|
2022-10-26 12:34:32 +00:00
|
|
|
const changeSongState = () => {
|
|
|
|
if (song.value.playback_state === 'Stopped') {
|
|
|
|
play()
|
|
|
|
} else if (song.value.playback_state === 'Paused') {
|
|
|
|
playbackService.resume()
|
|
|
|
} else {
|
|
|
|
playbackService.pause()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|