hookehuyr

feat(AudioPlayer): 添加倍速播放功能并优化播放按钮样式

- 新增倍速播放控件,支持0.5x-2.0x多档调节
- 暴露倍速控制方法给父组件
- 修复播放按钮动画类名错误
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
54 </button> 54 </button>
55 <button 55 <button
56 @click="togglePlay" 56 @click="togglePlay"
57 - :class="{'paused': !isPlaying, 'opacity-50 cursor-not-allowed': isLoading}" 57 + :class="{'playing': isPlaying, 'opacity-50 cursor-not-allowed': isLoading}"
58 :disabled="isLoading" 58 :disabled="isLoading"
59 class="w-12 h-12 flex items-center justify-center rounded-full bg-blue-500 hover:bg-blue-600 transition-colors shadow-lg" 59 class="w-12 h-12 flex items-center justify-center rounded-full bg-blue-500 hover:bg-blue-600 transition-colors shadow-lg"
60 > 60 >
...@@ -72,8 +72,17 @@ ...@@ -72,8 +72,17 @@
72 </button> 72 </button>
73 </div> 73 </div>
74 74
75 - <!-- 播放列表按钮 --> 75 + <!-- 倍速播放和播放列表按钮 -->
76 - <div class="flex justify-end mt-4"> 76 + <div class="flex justify-between items-center mt-4">
77 + <!-- 倍速播放控件 -->
78 + <button
79 + @click="cycleSpeed"
80 + class="flex items-center space-x-1 text-gray-500 hover:text-gray-700 transition-colors px-2 py-1 rounded-md hover:bg-gray-100"
81 + >
82 + <span class="text-sm font-medium">{{ speed }}x</span>
83 + </button>
84 +
85 + <!-- 播放列表按钮 -->
77 <button @click="togglePlaylist" class="text-gray-500 hover:text-gray-700 transition-colors"> 86 <button @click="togglePlaylist" class="text-gray-500 hover:text-gray-700 transition-colors">
78 <font-awesome-icon icon="list" class="text-lg" /> 87 <font-awesome-icon icon="list" class="text-lg" />
79 </button> 88 </button>
...@@ -146,6 +155,7 @@ const volume = ref(100) // 音量值 ...@@ -146,6 +155,7 @@ const volume = ref(100) // 音量值
146 const isPlaylistVisible = ref(false) // 播放列表显示状态 155 const isPlaylistVisible = ref(false) // 播放列表显示状态
147 const speed = ref(1.0) // 播放速度 156 const speed = ref(1.0) // 播放速度
148 const meta_id = ref(null) // 音频meta_id 157 const meta_id = ref(null) // 音频meta_id
158 +const speedOptions = [0.5, 0.75, 1.0, 1.25, 1.5, 2.0] // 倍速选项
149 159
150 // 计算属性 160 // 计算属性
151 const currentSong = computed(() => props.songs[currentIndex.value]) // 当前播放的歌曲 161 const currentSong = computed(() => props.songs[currentIndex.value]) // 当前播放的歌曲
...@@ -484,6 +494,34 @@ watch([isPlaying, currentIndex], () => { ...@@ -484,6 +494,34 @@ watch([isPlaying, currentIndex], () => {
484 } 494 }
485 }) 495 })
486 496
497 +// 倍速播放相关方法
498 +/**
499 + * 循环切换播放速度
500 + */
501 +const cycleSpeed = () => {
502 + const currentIndex = speedOptions.indexOf(speed.value)
503 + const nextIndex = (currentIndex + 1) % speedOptions.length
504 + const newSpeed = speedOptions[nextIndex]
505 +
506 + speed.value = newSpeed
507 + if (audio.value) {
508 + audio.value.playbackRate = newSpeed
509 + }
510 +}
511 +
512 +/**
513 + * 改变播放速度
514 + * @param {number} newSpeed - 新的播放速度
515 + */
516 +const changeSpeed = (newSpeed) => {
517 + speed.value = newSpeed
518 + if (audio.value) {
519 + audio.value.playbackRate = newSpeed
520 + }
521 +}
522 +
523 +
524 +
487 525
488 // 暴露给父组件的方法 526 // 暴露给父组件的方法
489 defineExpose({ 527 defineExpose({
...@@ -502,6 +540,8 @@ defineExpose({ ...@@ -502,6 +540,8 @@ defineExpose({
502 isPlaying: () => isPlaying.value, 540 isPlaying: () => isPlaying.value,
503 id: props.id, 541 id: props.id,
504 getPlayer: () => audio.value, 542 getPlayer: () => audio.value,
543 + changeSpeed, // 暴露倍速控制方法
544 + getCurrentSpeed: () => speed.value, // 暴露获取当前速度方法
505 }) 545 })
506 </script> 546 </script>
507 547
...@@ -554,7 +594,7 @@ button:not(:disabled) { ...@@ -554,7 +594,7 @@ button:not(:disabled) {
554 } 594 }
555 } 595 }
556 596
557 -button.paused .fa-pause { 597 +button.playing .fa-pause {
558 animation: pulse 1.5s infinite; 598 animation: pulse 1.5s infinite;
559 } 599 }
560 600
......