Skip to content

feat(player): 添加杜比全景声支持、MPV服务优化及缓存MD5校验#930

Open
laoshuikaixue wants to merge 2 commits intoimsyy:devfrom
laoshuikaixue:feature/dolby-atmos-support
Open

feat(player): 添加杜比全景声支持、MPV服务优化及缓存MD5校验#930
laoshuikaixue wants to merge 2 commits intoimsyy:devfrom
laoshuikaixue:feature/dolby-atmos-support

Conversation

@laoshuikaixue
Copy link
Contributor

  • 添加杜比全景声音质支持,使用旧版接口并传入特殊参数
  • 实现杜比音质自动降级机制,当歌曲不支持时自动切换到最高可用音质
  • 添加 MPV 服务重启前的清理逻辑,确保进程正确停止避免资源占用
  • 优化 MPV 进程启动参数,增加音频通道自动检测和损坏数据容错处理
  • 添加 MPV 进程输出捕获用于调试,记录标准输出和错误输出
  • 修改 cookie 设置添加 os=pc 参数以支持杜比音质数据获取
  • 修复音质控制组件中当前音质显示的逻辑错误
  • 统一新旧接口数据结构处理,兼容数组和对象格式返回值

Closed #875

- 添加杜比全景声音质支持,使用旧版接口并传入特殊参数
- 实现杜比音质自动降级机制,当歌曲不支持时自动切换到最高可用音质
- 添加 MPV 服务重启前的清理逻辑,确保进程正确停止避免资源占用
- 优化 MPV 进程启动参数,增加音频通道自动检测和损坏数据容错处理
- 添加 MPV 进程输出捕获用于调试,记录标准输出和错误输出
- 修改 cookie 设置添加 os=pc 参数以支持杜比音质数据获取
- 修复音质控制组件中当前音质显示的逻辑错误
- 统一新旧接口数据结构处理,兼容数组和对象格式返回值
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @laoshuikaixue, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求主要围绕提升用户音频体验和增强播放器稳定性展开。核心改动是引入了杜比全景声音质支持,并为此设计了智能降级策略,确保在不同歌曲和设备兼容性下的最佳音质体验。同时,对 MPV 播放器服务进行了多项优化,包括启动参数调整、资源清理和调试信息捕获,显著提升了播放器的健壮性和可维护性。此外,还修复了音质显示问题并改进了数据接口的兼容性。

Highlights

  • 杜比全景声音质支持: 添加了对杜比全景声音质的支持,通过旧版接口并传入特定参数来获取杜比音源。
  • 杜比音质自动降级: 实现了杜比音质的自动降级机制,当歌曲不支持杜比时,会自动切换到最高可用的音质(如 Hi-Res、无损或极高音质)。
  • MPV 服务管理优化: 在应用重启前增加了 MPV 服务的清理逻辑,确保 MPV 进程正确停止并释放资源,避免僵尸进程。
  • MPV 启动参数与调试: 优化了 MPV 进程的启动参数,增加了音频通道自动检测和损坏数据容错处理。同时,捕获了 MPV 进程的标准输出和错误输出,以便于调试。
  • Cookie 参数调整: 修改了请求的 Cookie 设置,添加了 os=pc 参数,以确保能够正确获取杜比音质相关数据。
  • 音质控制组件修复: 修复了音质控制组件中当前播放音质显示不准确的逻辑错误。
  • 接口数据结构兼容: 统一了新旧接口返回数据结构的处理方式,使其能够兼容数组和对象两种格式的返回值。
Changelog
  • electron/main/ipc/ipc-window.ts
    • 引入了 MpvService 和 processLog 模块
    • 在应用重启前增加了对 MPV 服务的停止和终止逻辑,以清理资源
  • electron/main/services/MpvService.ts
    • 为 MPV 进程添加了 --audio-channels=auto 参数以自动检测音频通道
    • 添加了 --demuxer-lavf-o=fflags=+discardcorrupt 参数以增强对损坏数据的容错处理
    • 修改了 MPV 进程的 stdio 配置,使其能够捕获标准输出和错误输出用于调试
    • 为 MPV 进程的退出事件增加了日志记录,包含退出码和信号
  • native/external-media-integration/src/model.rs
    • set_volume 函数添加了 #[cfg_attr(not(target_os = "linux"), allow(dead_code))] 属性,以避免在非 Linux 系统上出现死代码警告
  • src/api/song.ts
    • songUrl 函数的 level 类型中新增了 dolby 选项
    • dolby 级别的音质请求实现了特殊处理,调用旧版 /song/url 接口并传入 immerseType: 'c51' 参数
  • src/composables/useQualityControl.ts
    • 修复了 currentQualityLevel 计算逻辑,使其在未找到匹配音质时返回当前音质而非默认设置
    • 将音质选项的字体加粗逻辑从 isDefaultQuality 更改为 isPlayingQuality,以正确高亮当前播放音质
  • src/core/player/SongManager.ts
    • 引入了 songQuality API 用于检查歌曲的音质支持情况
    • 在获取歌曲 URL 时,如果请求杜比音质,会先检查歌曲是否支持,若不支持则自动降级到 Hi-Res、无损或极高音质
    • 统一了 songUrl 接口返回数据结构的处理,兼容数组和对象格式
    • 调整了音质判断逻辑,当请求杜比音质时,直接标记为杜比音质,否则根据返回数据判断
  • src/utils/request.ts
    • 在请求的 Cookie 中添加了 os=pc 参数,以支持杜比音质数据获取
Activity
  • 此拉取请求自创建以来,尚未有评论或评审活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Dolby Atmos support, optimizes MPV service management, and refines audio quality handling. Key changes include adding Dolby Atmos quality to song URL requests, implementing an automatic fallback mechanism for Dolby quality, and enhancing MPV process management by stopping it before application restarts and improving its startup parameters. Additionally, it fixes a logic error in quality display and unifies data structures for API responses. The changes improve audio quality options and application stability.

@@ -1,11 +1,13 @@
import { app, BrowserWindow, ipcMain } from "electron";
import { MpvService } from "../services/MpvService";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The MpvService import is added but not used in this file. It's good practice to remove unused imports to keep the codebase clean and avoid potential confusion.

Suggested change
import { MpvService } from "../services/MpvService";
import { app, BrowserWindow, ipcMain } from "electron";
import { useStore } from "../store";

import mainWindow from "../windows/main-window";
import loadWindow from "../windows/load-window";
import loginWindow from "../windows/login-window";
import { processLog } from "../logger";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The processLog import is added but not used in this file. It's good practice to remove unused imports to keep the codebase clean and avoid potential confusion.

Suggested change
import { processLog } from "../logger";
import loginWindow from "../windows/login-window";
/** 是否已首次启动 */

Comment on lines +71 to +72
"--audio-channels=auto", // 自动检测音频通道
"--demuxer-lavf-o=fflags=+discardcorrupt", // 容错处理,忽略损坏的数据
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comments for --audio-channels=auto and --demuxer-lavf-o=fflags=+discardcorrupt are in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase, especially for technical parameters that might be understood by a broader audience.

Suggested change
"--audio-channels=auto", // 自动检测音频通道
"--demuxer-lavf-o=fflags=+discardcorrupt", // 容错处理,忽略损坏的数据
"--audio-channels=auto", // Automatically detect audio channels
"--demuxer-lavf-o=fflags=+discardcorrupt", // Error tolerance, ignore corrupt data

| "hires"
| "jyeffect"
| "sky"
| "dolby"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Adding 'dolby' to the level type union is correct for supporting Dolby Atmos. However, ensure that all call sites for songUrl are updated to handle this new level type appropriately, especially where level is cast to any (e.g., in SongManager.ts). It's better to refine the type inference or create specific overloads if the dolby level has distinct parameters or behavior.

Suggested change
| "dolby"
| "sky"
| "dolby"

Comment on lines +42 to +52
// 杜比全景声使用旧版接口,并传入特殊参数
if (level === "dolby") {
return request({
url: "/song/url",
params: {
id,
br: 999000,
immerseType: "c51",
timestamp: Date.now(),
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment // 杜比全景声使用旧版接口,并传入特殊参数 is in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase.

Suggested change
// 杜比全景声使用旧版接口,并传入特殊参数
if (level === "dolby") {
return request({
url: "/song/url",
params: {
id,
br: 999000,
immerseType: "c51",
timestamp: Date.now(),
},
});
// Dolby Atmos uses the old interface and passes special parameters
if (level === "dolby") {
return request({
url: "/song/url",
params: {
id,
br: 999000,
immerseType: "c51",
timestamp: Date.now(),
},
});
}

Comment on lines +184 to +203
if (level === "dolby") {
try {
const qualityRes = await songQuality(id);
const hasDb = qualityRes.data?.db && Number(qualityRes.data.db.br) > 0;
// 如果不支持杜比,降级到最高可用音质
if (!hasDb) {
console.log(`🔽 [${id}] 歌曲不支持杜比音质,自动降级`);
// 按优先级降级:hires -> lossless -> exhigh
if (qualityRes.data?.hr && Number(qualityRes.data.hr.br) > 0) {
level = "hires";
} else if (qualityRes.data?.sq && Number(qualityRes.data.sq.br) > 0) {
level = "lossless";
} else {
level = "exhigh";
}
}
} catch (e) {
console.error(`检查杜比音质支持失败,降级到极高音质:`, e);
level = "exhigh";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for Dolby Atmos fallback is well-implemented, prioritizing hires, then lossless, and finally exhigh. However, the console.log and console.error messages are in Chinese. For consistency and maintainability, it's recommended to use English messages throughout the codebase.

    if (level === "dolby") {
      try {
        const qualityRes = await songQuality(id);
        const hasDb = qualityRes.data?.db && Number(qualityRes.data.db.br) > 0;
        // If Dolby is not supported, downgrade to the highest available quality
        if (!hasDb) {
          console.log(`🔽 [${id}] Song does not support Dolby Atmos, automatically downgrading`);
          // Downgrade by priority: hires -> lossless -> exhigh
          if (qualityRes.data?.hr && Number(qualityRes.data.hr.br) > 0) {
            level = "hires";
          } else if (qualityRes.data?.sq && Number(qualityRes.data.sq.br) > 0) {
            level = "lossless";
          } else {
            level = "exhigh";
          }
        }
      } catch (e) {
        console.error(`Failed to check Dolby Atmos support, downgrading to exhigh quality:`, e);
        level = "exhigh";
      }
    }

Comment on lines +209 to +210
// 兼容新旧接口的数据结构
const songData = Array.isArray(res.data) ? res.data[0] : res.data?.[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment // 兼容新旧接口的数据结构 is in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase.

Suggested change
// 兼容新旧接口的数据结构
const songData = Array.isArray(res.data) ? res.data[0] : res.data?.[0];
// Compatible with new and old interface data structures
const songData = Array.isArray(res.data) ? res.data[0] : res.data?.[0];

Comment on lines +226 to +234
// 获取音质:如果请求的是杜比,直接使用杜比音质,否则从返回数据判断
let quality: QualityType | undefined;
if (level === "dolby") {
// 请求的是杜比音质,直接标记为杜比
quality = QualityType.Dolby;
} else {
// 其他音质从返回数据判断
quality = handleSongQuality(songData, "online");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comments for determining song quality based on the level are in Chinese. For consistency and maintainability, it's recommended to use English comments throughout the codebase.

Suggested change
// 获取音质:如果请求的是杜比,直接使用杜比音质,否则从返回数据判断
let quality: QualityType | undefined;
if (level === "dolby") {
// 请求的是杜比音质,直接标记为杜比
quality = QualityType.Dolby;
} else {
// 其他音质从返回数据判断
quality = handleSongQuality(songData, "online");
}
// Get quality: if Dolby was requested, use Dolby quality directly, otherwise determine from returned data
let quality: QualityType | undefined;
if (level === "dolby") {
// If Dolby quality was requested, directly mark as Dolby
quality = QualityType.Dolby;
} else {
// Other qualities are determined from the returned data
quality = handleSongQuality(songData, "online");
}

@laoshuikaixue
Copy link
Contributor Author

使用旧版接口是因为新版接口获取到的数据不正确,相关功能在Windows平台测试没有问题

- 在music-cache-check IPC接口中新增md5参数支持
- 实现文件MD5计算方法用于缓存完整性验证
- 添加缓存文件MD5不匹配时自动删除机制
- 在SongManager中传递歌曲MD5进行缓存校验
- 优化缓存检查逻辑支持精确和模糊查找模式
@laoshuikaixue laoshuikaixue marked this pull request as draft February 23, 2026 10:43
@laoshuikaixue laoshuikaixue marked this pull request as ready for review February 23, 2026 10:57
@laoshuikaixue laoshuikaixue changed the title feat(player): 添加杜比音质支持并优化 MPV 服务管理 feat(player): 添加杜比全景声支持、MPV服务优化及缓存MD5校验 Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

杜比全景声在Windows下无法播放

1 participant