feat: 添加B站音频URL获取功能,优化播放器逻辑,删除不再使用的BilibiliPlayer和MusicBar组件

This commit is contained in:
alger
2025-03-30 01:20:28 +08:00
parent 477f8bb99b
commit 1a440fad09
17 changed files with 464 additions and 611 deletions
+24
View File
@@ -2,6 +2,7 @@ import { createDiscreteApi } from 'naive-ui';
import { computed, nextTick, onUnmounted, ref, watch } from 'vue';
import i18n from '@/../i18n/renderer';
import { getBilibiliAudioUrl } from '@/api/bilibili';
import useIndexedDB from '@/hooks/IndexDBHook';
import { audioService } from '@/services/audioService';
import pinia, { usePlayerStore } from '@/store';
@@ -235,6 +236,29 @@ watch(
initialPosition = savedProgress.progress;
}
// 对于B站视频,检查URL是否有效
if (playMusic.value.source === 'bilibili' && (!newVal || newVal === 'undefined')) {
console.log('B站视频URL无效,尝试重新获取');
// 需要重新获取B站视频URL
if (playMusic.value.bilibiliData) {
try {
const proxyUrl = await getBilibiliAudioUrl(
playMusic.value.bilibiliData.bvid,
playMusic.value.bilibiliData.cid
);
// 设置URL到播放器状态
(playMusic.value as any).playMusicUrl = proxyUrl;
playerStore.playMusicUrl = proxyUrl;
newVal = proxyUrl;
} catch (error) {
console.error('获取B站音频URL失败:', error);
return;
}
}
}
// 播放新音频,传递是否应该播放的状态
const newSound = await audioService.play(newVal, playMusic.value, shouldPlay);
sound.value = newSound as Howl;
+2 -2
View File
@@ -12,7 +12,7 @@ import { getImageLinearBackground } from '@/utils/linearColor';
const musicHistory = useMusicHistory();
// 获取歌曲url
export const getSongUrl = async (id: number, songData: any, isDownloaded: boolean = false) => {
export const getSongUrl = async (id: any, songData: any, isDownloaded: boolean = false) => {
const { data } = await getMusicUrl(id, isDownloaded);
let url = '';
let songDetail = null;
@@ -247,7 +247,7 @@ export const useMusicListHook = () => {
};
// 异步加载歌词的方法
const loadLrcAsync = async (state: any, playMusicId: number) => {
const loadLrcAsync = async (state: any, playMusicId: any) => {
if (state.playMusic.lyric && state.playMusic.lyric.lrcTimeArray.length > 0) {
return;
}