2022-10-26 12:34:32 +00:00
|
|
|
<template>
|
2022-10-28 23:59:04 +00:00
|
|
|
<div :style="{ backgroundImage: `url(${defaultCover})` }" class="cover">
|
2024-02-24 15:37:01 +00:00
|
|
|
<img
|
|
|
|
v-koel-hide-broken-icon
|
|
|
|
:alt="song.album_name"
|
|
|
|
:src="song.album_cover"
|
|
|
|
class="pointer-events-none"
|
|
|
|
loading="lazy"
|
|
|
|
>
|
2022-11-29 10:18:58 +00:00
|
|
|
<a :title="title" class="control" role="button" @click.prevent="changeSongState">
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="song.playback_state === 'Playing' ? faPause : faPlay" class="text-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>
|
|
|
|
|
2024-04-04 20:13:35 +00:00
|
|
|
<style lang="postcss" scoped>
|
2022-10-26 12:34:32 +00:00
|
|
|
.cover {
|
|
|
|
width: 48px;
|
|
|
|
min-width: 48px;
|
|
|
|
aspect-ratio: 1/1;
|
|
|
|
background-size: cover;
|
|
|
|
position: relative;
|
|
|
|
border-radius: 4px;
|
|
|
|
overflow: hidden;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
|
2022-10-28 23:59:04 +00:00
|
|
|
img {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
object-fit: cover;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
2022-10-26 12:34:32 +00:00
|
|
|
&::before {
|
|
|
|
content: " ";
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
pointer-events: none;
|
|
|
|
background: #000;
|
|
|
|
opacity: 0;
|
2022-10-28 23:59:04 +00:00
|
|
|
z-index: 1;
|
2022-10-26 12:34:32 +00:00
|
|
|
|
|
|
|
@media (hover: none) {
|
|
|
|
opacity: .7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.control {
|
|
|
|
border-radius: 50%;
|
|
|
|
width: 28px;
|
|
|
|
height: 28px;
|
|
|
|
background: rgba(0, 0, 0, .5);
|
|
|
|
font-size: 1rem;
|
|
|
|
z-index: 1;
|
|
|
|
display: none;
|
|
|
|
color: var(--color-text-primary);
|
|
|
|
transition: .3s;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
@media (hover: none) {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|