|
| 1 | +<template> |
| 2 | + <div style="padding: 20px"> |
| 3 | + <LyricPlayer |
| 4 | + :audioSrc="musicMp3" |
| 5 | + :lyricSource="lyricLrc" |
| 6 | + :parseOptions="{ isWordSplit: true }" |
| 7 | + :align="'center'" |
| 8 | + :theme="customTheme" |
| 9 | + :baseTime="0.5" |
| 10 | + :height="'60vh'" |
| 11 | + :showAudioControl="true" |
| 12 | + @lyric-change="handleLyricChange" |
| 13 | + @audio-play="handleAudioPlay" |
| 14 | + /> |
| 15 | + </div> |
| 16 | +</template> |
| 17 | + |
| 18 | +<script setup lang="ts"> |
| 19 | +import { reactive } from 'vue' |
| 20 | +import { LyricPlayer } from '@lyric-render/vue' |
| 21 | +import lyricLrc from './lyric.lrc?raw' |
| 22 | +import musicMp3 from './music.mp3' |
| 23 | +
|
| 24 | +// 自定义主题 |
| 25 | +const customTheme = reactive({ |
| 26 | + container: { bg: '#1a1a1a', border: '1px solid #333', padding: '0 16px' }, |
| 27 | + normal: { color: '#999', fontSize: '14px' }, |
| 28 | + highlight: { color: '#FFD700', fontSize: '16px' }, |
| 29 | + state: { color: '#666', fontSize: '14px' }, |
| 30 | +}) |
| 31 | +
|
| 32 | +// 歌词变化回调 |
| 33 | +const handleLyricChange = (index: number, item: any) => { |
| 34 | + console.log('当前歌词索引:', index, '歌词内容:', item?.text) |
| 35 | +} |
| 36 | +
|
| 37 | +// 音频播放状态回调 |
| 38 | +const handleAudioPlay = (isPlaying: boolean) => { |
| 39 | + console.log('音频播放状态:', isPlaying) |
| 40 | +} |
| 41 | +</script> |
| 42 | + |
| 43 | +<style> |
| 44 | +* { |
| 45 | + margin: 0; |
| 46 | + padding: 0; |
| 47 | + box-sizing: border-box; |
| 48 | +} |
| 49 | +
|
| 50 | +body { |
| 51 | + font-family: Arial, sans-serif; |
| 52 | + background-color: #f5f5f5; |
| 53 | +} |
| 54 | +</style> |
0 commit comments