In the following python code I get the currently playing media / music from windows. To display it on a electron app i would prefer to get the data using Node.js (or Rust for Tauri):
import asyncio
from winrt.windows.media.control import \
GlobalSystemMediaTransportControlsSessionManager as MediaManager
async def get_current_media_info():
sessions = await MediaManager.request_async()
current_session = sessions.get_current_session()
if current_session:
info = await current_session.try_get_media_properties_async()
return info
return None
if __name__ == "__main__":
info = asyncio.run(get_current_media_info())
if info:
print(f"Currently playing: {info.thumbnail} by {info.artist}")
else:
print("No media is currently playing")
Made it in rust
main.rs
use windows::Media::Control::{GlobalSystemMediaTransportControlsSessionManager as MediaSessionManager, GlobalSystemMediaTransportControlsSession};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[tokio::main]
async fn main() -> Result<()> {
let session_manager = MediaSessionManager::RequestAsync()?.await?;
let sessions = session_manager.GetCurrentSession()?;
let info = sessions.TryGetMediaPropertiesAsync()?.await?;
let title = info.Title()?;
println!("{}", title);
Ok(())
}
cargo.toml
[dependencies]
tokio = { version = "1.37.0", features = ["full"] }
windows = { version = "0.56.0", features = ["Media_Control"]}