feature: tap the lyric line to go to corresponding progress

This commit is contained in:
alikia2x 2024-07-29 18:22:19 +08:00
parent d248a1a084
commit 0f01c05830
4 changed files with 20 additions and 25 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "aquavox", "name": "aquavox",
"version": "1.13.0", "version": "1.14.0",
"private": false, "private": false,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",

View File

@ -24,7 +24,6 @@
let isInfoTopOverflowing = false; let isInfoTopOverflowing = false;
let songInfoTopContainer: HTMLDivElement; let songInfoTopContainer: HTMLDivElement;
let songInfoTopContent: HTMLSpanElement; let songInfoTopContent: HTMLSpanElement;
let lastTouchProgress: number;
let userAdjustingVolume = false; let userAdjustingVolume = false;
const mql = window.matchMedia('(max-width: 1280px)'); const mql = window.matchMedia('(max-width: 1280px)');

View File

@ -11,6 +11,7 @@
export let lyrics: string[]; export let lyrics: string[];
export let originalLyrics: LrcJsonData; export let originalLyrics: LrcJsonData;
export let progress: number; export let progress: number;
export let player: HTMLAudioElement | null;
// Local state and variables // Local state and variables
let getLyricIndex: Function; let getLyricIndex: Function;
@ -289,6 +290,12 @@
} }
}); });
function lyricClick(lyricIndex: number) {
if (player===null || originalLyrics.scripts === undefined) return;
player.currentTime = originalLyrics.scripts[lyricIndex].start;
player.play()
}
</script> </script>
<svelte:window on:keydown={onKeyDown} /> <svelte:window on:keydown={onKeyDown} />
@ -317,7 +324,7 @@
on:scroll={scrollHandler} on:scroll={scrollHandler}
> >
{#each lyrics as lyric, i} {#each lyrics as lyric, i}
<div bind:this={_refs[i]} class="relative h-fit text-shadow-lg"> <div bind:this={_refs[i]} class="relative h-fit text-shadow-lg" on:click={() => {lyricClick(i)}}>
{#if debugMode && refs[i] && refs[i].style !== undefined} {#if debugMode && refs[i] && refs[i].style !== undefined}
<span class="previous-lyric !text-lg !absolute !-translate-y-12">{i} &nbsp; <span class="previous-lyric !text-lg !absolute !-translate-y-12">{i} &nbsp;
{originalLyrics.scripts[i].start} ~ {originalLyrics.scripts[i].end} {originalLyrics.scripts[i].start} ~ {originalLyrics.scripts[i].end}
@ -325,7 +332,7 @@
top: {Math.round(refs[i].getBoundingClientRect().top)}px top: {Math.round(refs[i].getBoundingClientRect().top)}px
</span> </span>
{/if} {/if}
<p class={`${getClass(i, progress)}`}> <p class={`${getClass(i, progress)} hover:bg-[rgba(200,200,200,0.2)] pl-2 rounded-lg duration-300 cursor-pointer `}>
{lyric} {lyric}
</p> </p>
{#if originalLyrics.scripts[i].translation && showTranslation} {#if originalLyrics.scripts[i].translation && showTranslation}
@ -397,26 +404,6 @@
top: 1rem; top: 1rem;
} }
@media (min-width: 768px) {
.current-lyric {
font-size: 3rem;
line-height: 4rem;
margin: 2.4rem 0;
}
.after-lyric {
font-size: 3rem;
line-height: 3.3rem;
margin: 2.4rem 0;
}
.previous-lyric {
font-size: 3em;
line-height: 3.3rem;
margin: 2.4rem 0;
}
}
@media (min-width: 1024px) { @media (min-width: 1024px) {
.current-lyric { .current-lyric {
font-size: var(--lyric-desktop-font-size); font-size: var(--lyric-desktop-font-size);

View File

@ -202,14 +202,23 @@
{hasLyrics} {hasLyrics}
/> />
<Lyrics lyrics={lyricsText} {originalLyrics} progress={currentProgress}/> <Lyrics lyrics={lyricsText} {originalLyrics} progress={currentProgress} player={audioPlayer}/>
<audio <audio
bind:this={audioPlayer} bind:this={audioPlayer}
controls controls
style="display: none" style="display: none"
on:play={() => {
if (audioPlayer===null) return;
paused = audioPlayer.paused;
}}
on:pause={() => {
if (audioPlayer===null) return;
paused = audioPlayer.paused;
}}
on:ended={() => { on:ended={() => {
paused = true; paused = true;
if (audioPlayer == null) return;
audioPlayer.pause(); audioPlayer.pause();
}} }}
></audio> ></audio>