koel/resources/assets/js/components/song/SongThumbnail.vue

62 lines
1.9 KiB
Vue
Raw Normal View History

<template>
2024-05-19 05:49:42 +00:00
<button
2024-04-04 22:20:42 +00:00
:style="{ backgroundImage: `url(${defaultCover})` }"
2024-05-19 05:49:42 +00:00
:title="title"
class="song-thumbnail w-[48px] aspect-square bg-cover relative rounded overflow-hidden active:scale-95"
@click.prevent="playOrPause"
2024-04-04 22:20:42 +00:00
>
2024-02-24 15:37:01 +00:00
<img
v-koel-hide-broken-icon
2024-05-19 05:49:42 +00:00
alt="Cover image"
:src="src"
class="w-full aspect-square object-cover"
2024-02-24 15:37:01 +00:00
loading="lazy"
>
<span class="absolute top-0 left-0 w-full h-full group-hover:bg-black/40 no-hover:bg-black/40 z-10" />
2024-05-19 05:49:42 +00:00
<span
class="absolute flex opacity-0 no-hover:opacity-100 items-center justify-center w-[24px] aspect-square rounded-full top-1/2
2024-05-19 05:49:42 +00:00
left-1/2 -translate-x-1/2 -translate-y-1/2 bg-k-highlight group-hover:opacity-100 duration-500 transition z-20"
2024-04-04 22:20:42 +00:00
>
<Icon v-if="playable.playback_state === 'Playing'" :icon="faPause" class="text-white" />
2024-05-19 05:49:42 +00:00
<Icon v-else :icon="faPlay" class="text-white ml-0.5" />
</span>
</button>
</template>
<script lang="ts" setup>
import { computed, toRefs } from 'vue'
import { faPause, faPlay } from '@fortawesome/free-solid-svg-icons'
2024-05-19 05:49:42 +00:00
import { defaultCover, getPlayableProp } from '@/utils'
import { playbackService } from '@/services'
const props = defineProps<{ playable: Playable }>()
const { playable } = toRefs(props)
const src = computed(() => getPlayableProp<string>(playable.value, 'album_cover', 'episode_image'))
2024-05-19 05:49:42 +00:00
const play = () => playbackService.play(playable.value)
const title = computed(() => {
if (playable.value.playback_state === 'Playing') {
return 'Pause'
}
if (playable.value.playback_state === 'Paused') {
return 'Resume'
}
return 'Play'
})
2024-06-07 12:53:24 +00:00
const playOrPause = async () => {
if (playable.value.playback_state === 'Stopped') {
// @todo play at the right playback position for Episodes
2024-06-07 12:53:24 +00:00
await play()
} else if (playable.value.playback_state === 'Paused') {
2024-06-07 12:53:24 +00:00
await playbackService.resume()
} else {
playbackService.pause()
}
}
</script>