音乐控制/解密

This commit is contained in:
LFeng committed 2026-09-28 00:21:12 +08:00
1 parent 9e6d73e191
commit ff1d5cd517
41 files changed
+10827 -4

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
//! GSMTC 可用性探测(MUSIC_REMOTE_PLAN §7 P0 第 1 项 / §6 第 1 条)
//!
//! 关键假设:GSMTC(Windows.Media.Control)在**非打包**桌面应用可用(Windows 10 1809+)。
//! 本 example 以普通控制台进程运行(无 package identity),跑通即证明假设成立。
//!
//! 运行:`cargo run --example gsmtc_probe`
//! 建议先在任意播放器(网易云/浏览器/Thing)放一首歌,可看到当前会话的元数据与时间轴。
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager;
use windows::core::Result;
fn main() -> Result<()> {
// 1. 取全局会话管理器(失败 = 整个能力需降级,见计划 §3.1 失败策略)
let mgr = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?;
// 2. 枚举系统全部 SMTC 会话(注意:0.52 投影里 GetSessions/GetCurrentSession 是同步的)
let sessions = mgr.GetSessions()?;
println!("[ok] GSMTC 可用(unpackaged),当前会话数: {}", sessions.Size()?);
// 3. 当前活跃会话的元数据 / 播放状态 / 时间轴
// 无会话时 ABI 返回 null → windows-rs 投影为 Err(E_POINTER),按"无会话"处理
match mgr.GetCurrentSession() {
Ok(cur) => {
println!("current: {}", cur.SourceAppUserModelId()?);
let p = cur.TryGetMediaPropertiesAsync()?.get()?;
println!(" {} - {} | album: {}", p.Artist()?, p.Title()?, p.AlbumTitle()?);
println!(" status: {:?}", cur.GetPlaybackInfo()?.PlaybackStatus()?);
let tl = cur.GetTimelineProperties()?;
println!(
" position(ticks): {} | lastUpdated(ticks): {}",
tl.Position()?.Duration,
tl.LastUpdatedTime()?.UniversalTime
);
}
Err(e) => println!("current session: <none> ({e})(先放一首歌再跑,可看完整元数据)"),
}
Ok(())
}