60 lines
2.1 KiB
Rust
60 lines
2.1 KiB
Rust
//! 诊断:枚举全部 GSMTC 会话的时间轴原始值(判断"来源不提供进度"的形态)。
|
|
//!
|
|
//! 运行:`cargo run --example gsmtc_dump`
|
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager;
|
|
|
|
fn ticks_to_unix_ms(ticks: i64) -> i64 {
|
|
ticks / 10_000 - 62_135_596_800_000
|
|
}
|
|
|
|
fn main() -> windows::core::Result<()> {
|
|
let mgr = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?;
|
|
let sessions = mgr.GetSessions()?;
|
|
let now_ms = SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.map(|d| d.as_millis() as i64)
|
|
.unwrap_or(0);
|
|
println!("now(unix ms) = {now_ms}");
|
|
println!("sessions = {}", sessions.Size()?);
|
|
|
|
for i in 0..sessions.Size()? {
|
|
let s = sessions.GetAt(i)?;
|
|
println!("--- [{}] {}", i, s.SourceAppUserModelId()?);
|
|
if let Ok(p) = s.TryGetMediaPropertiesAsync()?.get() {
|
|
println!(
|
|
" title={:?} artist={:?} album={:?}",
|
|
p.Title()?,
|
|
p.Artist()?,
|
|
p.AlbumTitle()?
|
|
);
|
|
}
|
|
let info = s.GetPlaybackInfo()?;
|
|
println!(" status={:?}", info.PlaybackStatus()?);
|
|
if let Ok(c) = info.Controls() {
|
|
println!(
|
|
" controls play={} pause={} next={} prev={} seek={}",
|
|
c.IsPlayEnabled().unwrap_or(false),
|
|
c.IsPauseEnabled().unwrap_or(false),
|
|
c.IsNextEnabled().unwrap_or(false),
|
|
c.IsPreviousEnabled().unwrap_or(false),
|
|
c.IsPlaybackPositionEnabled().unwrap_or(false)
|
|
);
|
|
}
|
|
let tl = s.GetTimelineProperties()?;
|
|
let pos = tl.Position()?.Duration;
|
|
let end = tl.EndTime().map(|t| t.Duration).unwrap_or(-1);
|
|
let upd = tl.LastUpdatedTime()?.UniversalTime;
|
|
let upd_ms = ticks_to_unix_ms(upd);
|
|
println!(
|
|
" position={}s end={}s lastUpdatedTicks={upd} -> unixMs={upd_ms} (deltaMs={})",
|
|
pos as f64 / 1e7,
|
|
end as f64 / 1e7,
|
|
upd_ms - now_ms
|
|
);
|
|
}
|
|
Ok(())
|
|
}
|