Skip to content

Commit

Permalink
🐞 fix: 修复网页端跨域 #317
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Dec 27, 2024
1 parent 96a0495 commit 1a61aa2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion electron/main/ipcMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ const initWinIpcMain = (
ipcMain.handle("get-music-files", async (_, dirPath: string) => {
try {
// 规范化路径
const filePath = resolve(dirPath);
const filePath = resolve(dirPath).replace(/\\/g, "/");
console.info(`📂 Fetching music files from: ${filePath}`);
// 查找指定目录下的所有音乐文件
const musicFiles = await fg("**/*.{mp3,wav,flac}", { cwd: filePath });
// 解析元信息
Expand Down
8 changes: 7 additions & 1 deletion src/components/Setting/PlaySetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@
<n-card class="set-item">
<div class="label">
<n-text class="name">音乐频谱</n-text>
<n-text class="tip" :depth="3">开启音乐频谱会极大影响性能,如遇问题请关闭</n-text>
<n-text class="tip" :depth="3">
{{
isElectron
? "开启音乐频谱会影响性能或音频输出切换等功能,如遇问题请关闭"
: "开启可能会造成无法播放或其他问题,如遇任何问题请关闭"
}}
</n-text>
</div>
<n-switch
class="set"
Expand Down
7 changes: 5 additions & 2 deletions src/utils/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,17 @@ class Player {
// 获取数据
const dataStore = useDataStore();
const statusStore = useStatusStore();
const settingStore = useSettingStore();
const playSongData = this.getPlaySongData();
// 获取配置
const { seek } = options;
// 初次加载
this.player.once("load", () => {
// 允许跨域
const audioDom = this.getAudioDom();
audioDom.crossOrigin = "anonymous";
if (settingStore.showSpectrums) {
const audioDom = this.getAudioDom();
audioDom.crossOrigin = "anonymous";
}
// 恢复进度( 需距离本曲结束大于 2 秒 )
if (seek && statusStore.duration - statusStore.currentTime > 2) this.setSeek(seek);
// 更新状态
Expand Down

0 comments on commit 1a61aa2

Please sign in to comment.