Skip to content

重构媒体控件相关集成#737

Merged
imsyy merged 17 commits into
SPlayer-Dev:devfrom
apoint123:refactor/refine-media-integration
Jan 16, 2026
Merged

重构媒体控件相关集成#737
imsyy merged 17 commits into
SPlayer-Dev:devfrom
apoint123:refactor/refine-media-integration

Conversation

@apoint123
Copy link
Copy Markdown
Member

@apoint123 apoint123 commented Jan 12, 2026

目前项目将不同平台的媒体控件拆分为了多个原生插件,导致前端需要进行大量判断什么平台应该加载什么插件、调用什么命令,此 PR 将所有媒体控件集中成为一个原生插件,通过条件编译指令实现不同平台的兼容性,前端无需任何判断。

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @apoint123, 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!

This pull request undertakes a significant refactoring effort to streamline how media controls are integrated across different platforms. By merging previously disparate native plugins into a single, cohesive module, the aim is to reduce complexity for frontend development and enhance maintainability. The changes introduce a unified interface for media interactions, abstracting away platform-specific details through conditional compilation, and enriching the data available for media presentation.

Highlights

  • Native Plugin Consolidation: The pull request centralizes all platform-specific media control native plugins (SMTC, Discord RPC, MPRIS) into a single, unified native plugin named external-media-integration. This significantly simplifies the project structure and frontend logic.
  • Frontend Simplification: The frontend no longer needs to manage multiple native plugin imports or implement platform-specific logic for loading and calling commands. All media control interactions will now go through the single external-media-integration module.
  • Enhanced Discord RPC Integration: Discord Rich Presence functionality is now integrated directly into the new unified plugin. This includes new configuration options for display mode and paused states, and more granular timeline updates (from seconds to milliseconds) for a smoother experience.
  • Improved Media Metadata: Media metadata structures (MetadataPayload, MetadataParam) have been extended to include original_cover_url and duration fields, providing more comprehensive information for media display and control.
  • Dependency Streamlining: The Cargo.lock and Cargo.toml files have been updated to reflect the removal of numerous individual native module dependencies and the introduction of the new consolidated external-media-integration package, along with updated napi and napi-derive versions.
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
Copy Markdown
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

你好,这次重构将多个媒体控件相关的原生插件整合为一个,这是一个很好的方向,能够简化前端的逻辑和后续的维护。代码的整体结构变得更加清晰了。

我在审查中发现了一些关于 Discord RPC 实现和资源管理的关键问题,需要你关注和修复。此外,还有一些配置文件中的小问题需要修正。请查看具体的审查评论。

Comment thread native/external-media-integration/src/discord.rs
Comment thread native/external-media-integration/src/lib.rs
Comment thread native/external-media-integration/package.json Outdated
Comment thread tsconfig.web.json Outdated
@apoint123 apoint123 force-pushed the refactor/refine-media-integration branch 3 times, most recently from f6e5622 to 5dca670 Compare January 12, 2026 16:29
@apoint123
Copy link
Copy Markdown
Member Author

/gemini review

@apoint123 apoint123 force-pushed the refactor/refine-media-integration branch from 8ef3e54 to 4b4dfe0 Compare January 13, 2026 08:59
@apoint123
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
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

你好,感谢你为这个项目做出的巨大贡献!这次重构将多个原生插件统一为一个,极大地简化了前端的平台判断逻辑,使得代码更加清晰和易于维护。通过在 Rust 中使用 trait 和条件编译来处理平台差异是一个非常出色的设计。我对一些可以改进的地方提出了一些建议,主要集中在确保资源能够被正确清理以及保证用户设置迁移的准确性上。总体来说,这是一次非常成功的重构,做得很好!

Comment thread native/external-media-integration/src/lib.rs
Comment thread src/stores/migrations/settingMigrations.ts
Comment thread native/external-media-integration/src/discord.rs
Comment thread src/core/player/MediaSessionManager.ts
@apoint123 apoint123 force-pushed the refactor/refine-media-integration branch from 03c92ec to a7d2f4f Compare January 13, 2026 17:46
@apoint123
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
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

这次重构做得非常出色,将多个原生插件统一为一个 external-media-integration 模块,极大地简化了代码结构和跨平台逻辑。通过 SystemMediaControls trait 抽象出平台差异,使得代码更清晰、更易于维护。文档和构建脚本的更新也非常及时和完善。

我在代码中发现了一些可以改进的地方,主要涉及 Linux 平台上的音量控制功能回归,以及 Discord RPC 实现中的一些细节。总体来说,这是一次高质量的重构,恭喜!

I am having trouble creating individual review comments. Click here to see my feedback.

electron/main/ipc/ipc-media.ts (252-261)

high

在这次重构中,media-update-volume 的 IPC 处理逻辑被移除了。之前的实现似乎允许通过 MPRIS D-Bus 接口控制 Linux 上的音量。
新的 external-media-integration 模块在构建 mpris_server::Player 时没有启用音量控制相关的能力(例如 can_control_volume),这可能会导致 Linux 用户失去通过系统媒体控件调节音量的功能。

如果这是一个无意的功能回归,建议在新的原生模块中重新实现对音量控制的支持。

native/external-media-integration/src/discord.rs (50)

medium

TIMESTAMP_UPDATE_THRESHOLD_MS 设置为 100ms 可能太低了。Discord RPC 对 API 调用有速率限制,过于频繁地更新时间戳(尤其是在正常播放期间,进度更新可能会以几百毫秒的间隔发生)可能会导致被限流。

之前的实现中,这个阈值是 2 秒。建议将此阈值调高,例如 15002000 毫秒,以避免不必要的 API 调用并减少被限流的风险。

const TIMESTAMP_UPDATE_THRESHOLD_MS: i64 = 1500;

native/external-media-integration/src/discord.rs (377-398)

medium

calc_playing_timestamps 函数中,当 current_time >= duration 时会返回 (0, 0)。然而,在 perform_update 函数中,调用方没有处理这个特殊的返回值。这会导致向 Discord 发送一个 start: 0, end: 0 的无效时间戳。

之前的代码实现中,对这种情况有专门的处理逻辑,会跳过时间戳的更新。建议在这里也加上类似的判断,当 calc_playing_timestamps 返回 (0, 0) 时,不为 Activity 设置时间戳。

例如,可以这样修改:

let (start, end) = Self::calc_playing_timestamps(data.current_time, duration);

if start == 0 && end == 0 {
    debug!("当前时间超过总时长,跳过时间戳更新");
    should_send = last_sent_end_timestamp.is_some();
    if should_send {
        warn!("没有有效时长,清除时间戳");
    }
} else {
    // 频繁调用 Discord RPC 接口会导致限流,所以在跳转发生时再更新时间戳
    if let Some(last_end) = last_sent_end_timestamp {
        let diff = (*last_end - end).abs();
        if diff < TIMESTAMP_UPDATE_THRESHOLD_MS {
            return true;
        }
        debug!(
            diff_ms = diff,
            threshold_ms = TIMESTAMP_UPDATE_THRESHOLD_MS,
            "进度变更超过阈值,触发更新"
        );
    }

    activity = activity.timestamps(Timestamps::new().start(start).end(end));
    new_end_timestamp = Some(end);
    should_send = true;
}

这样可以避免发送无效的时间戳,并保持与之前逻辑的一致性。

@apoint123 apoint123 marked this pull request as ready for review January 14, 2026 10:58
@apoint123 apoint123 force-pushed the refactor/refine-media-integration branch from 69db441 to 4c4c9ef Compare January 14, 2026 11:13
@apoint123 apoint123 force-pushed the refactor/refine-media-integration branch from 4c4c9ef to a0f5755 Compare January 14, 2026 13:43
@imsyy imsyy merged commit 5113af1 into SPlayer-Dev:dev Jan 16, 2026
@apoint123 apoint123 deleted the refactor/refine-media-integration branch January 16, 2026 03:06
@apoint123 apoint123 restored the refactor/refine-media-integration branch January 16, 2026 06:08
@apoint123 apoint123 deleted the refactor/refine-media-integration branch February 8, 2026 08:17
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.

2 participants