Dubya.WindowsMediaController
2.3.0
Versions contain multiple issues and will no longer be maintained/supported. Please use a non-deprecated version.
See the version list below for details.
dotnet add package Dubya.WindowsMediaController --version 2.3.0
NuGet\Install-Package Dubya.WindowsMediaController -Version 2.3.0
<PackageReference Include="Dubya.WindowsMediaController" Version="2.3.0" />
paket add Dubya.WindowsMediaController --version 2.3.0
#r "nuget: Dubya.WindowsMediaController, 2.3.0"
// Install Dubya.WindowsMediaController as a Cake Addin #addin nuget:?package=Dubya.WindowsMediaController&version=2.3.0 // Install Dubya.WindowsMediaController as a Cake Tool #tool nuget:?package=Dubya.WindowsMediaController&version=2.3.0
Windows Media Controller
This repository provides a wrapper for developers to more easily get information from and interact with the Windows 10/11 OS media interface.
This allows for a better understanding and control of the Media Sessions and can have many different applications. Some features include:
- Control playback on individual Media Sessions (Spotify, Chrome, etc)
- Get media information of currently playing (Song, Author, Thumbnail, etc)
Requirements
- Windows 10 (Build 17763+) or Windows 11
- The ability to talk to Windows Runtime. (In a majority of cases, this will not be an issue)
- .NET Framework 4.6+ or .NET Core 3.0+ or .NET 5+
- May need to be able to interact with the desktop
- In situations such as being run through Windows Task Scheduler, the application will need an active window to start with, you can hide it afterward.
NET Framework:
For .NET Framework, I've seen people encountering issues with how the package gets imported. If you run across this issue, add the package by adding this to the .csproj file. <br> (replacing '2.3.0' with the preferred NuGet version)
<ItemGroup>
<PackageReference Include="Dubya.WindowsMediaController">
<Version>2.3.0</Version>
</PackageReference>
</ItemGroup>
NET 5+:
NET 5 brought along a lot of changes in how WinRT is meant to be accessed. More of that info can be found here.
If you're doing a GUI app you should be good to go and be able to just import the lib.
However, for other cases, your TargetFramework
in the .csproj file needs to be modified before importing the package.
<br> (replacing net5.0 with desired .NET version)
<TargetFramework>net5.0-windows10.0.22000.0</TargetFramework>
How To Use
Initialization:
mediaManager = new MediaManager();
mediaManager.OnAnySessionOpened += MediaManager_OnAnySessionOpened;
mediaManager.OnAnySessionClosed += MediaManager_OnAnySessionClosed;
mediaManager.OnAnyMediaPropertyChanged += MediaManager_OnAnyMediaPropertyChanged;
mediaManager.OnAnyPlaybackStateChanged += MediaManager_OnAnyPlaybackStateChanged;
mediaManager.Start();
OR
mediaManager.StartAsync();
Class Structure:
MediaManager:
ReadOnlyDictionary<string, MediaSession> CurrentMediaSessions;
bool IsStarted { get; }
GlobalSystemMediaTransportControlsSessionManager WindowsSessionManager { get; }
void Start();
async Task StartAsync();
MediaSession GetFocusedSession();
void ForceUpdate();
delegate void OnAnySessionOpened(MediaManager.MediaSession session);
delegate void OnAnySessionClosed(MediaManager.MediaSession session);
delegate void OnFocusedSessionChanged(MediaManager.MediaSession session);
delegate void OnAnyMediaPropertyChanged(MediaManager.MediaSession sender, GlobalSystemMediaTransportControlsSessionMediaProperties args);
delegate void OnAnyPlaybackStateChanged(MediaManager.MediaSession sender, GlobalSystemMediaTransportControlsSessionPlaybackInfo args);
MediaManager.MediaSession:
readonly string Id;
GlobalSystemMediaTransportControlsSession ControlSession { get; }
delegate void OnSessionClosed(MediaManager.MediaSession session);
delegate void OnMediaPropertyChanged(MediaManager.MediaSession sender, GlobalSystemMediaTransportControlsSessionMediaProperties args);
delegate void OnPlaybackStateChanged(MediaManager.MediaSession sender, GlobalSystemMediaTransportControlsSessionPlaybackInfo args);
Getting Some Info:
Getting PlaybackInfo (Seeing what actions are available/Is paused or playing, etc)
- Returns: GlobalSystemMediaTransportControlsSessionPlaybackInfo
mediaSession.ControlSession.GetPlaybackInfo()
Getting current MediaProperties (Currently playing title, author, thumbnail, etc)
- Returns: GlobalSystemMediaTransportControlsSessionMediaProperties
await mediaSession.ControlSession.TryGetMediaPropertiesAsync()
Useful Microsoft Documentations:
- GlobalSystemMediaTransportControlsSessionManager - Located in
MediaManager.WindowsSessionManager
. This class allows for events whenever a source's state changes. - GlobalSystemMediaTransportControlsSession - Located in
MediaManager.MediaSession.ControlSession
. The Media Session that allows for events whenever the playback state or the media property changes as well as to grab such info whenever desired.
Samples
- Sample.CMD - A very barebone console application for developers to get a feel of how their use-case might act.
- Sample.UI - A WPF media controller
Credit
- Luca Marini (gitlab) - Helped me understand the Windows API
- Google (materialui) - Utilizing their play icon to create our icon
- Kinnara (ModernWpf) - Utilized the ModernWpf library to create the UI sample
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net5.0-windows10.0.22000 is compatible. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net6.0-windows10.0.22000 is compatible. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net7.0-windows10.0.22000 is compatible. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
.NET Framework | net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 was computed. |
-
.NETCoreApp 3.1
- Microsoft.Windows.SDK.Contracts (>= 10.0.22000.196)
-
.NETFramework 4.6.1
- Microsoft.Windows.SDK.Contracts (>= 10.0.22000.196)
-
.NETFramework 4.6.2
- Microsoft.Windows.SDK.Contracts (>= 10.0.22000.196)
-
.NETFramework 4.7
- Microsoft.Windows.SDK.Contracts (>= 10.0.22000.196)
-
.NETFramework 4.7.1
- Microsoft.Windows.SDK.Contracts (>= 10.0.22000.196)
-
.NETFramework 4.7.2
- Microsoft.Windows.SDK.Contracts (>= 10.0.22000.196)
-
.NETFramework 4.8
- Microsoft.Windows.SDK.Contracts (>= 10.0.22000.196)
-
net5.0-windows10.0.22000
- No dependencies.
-
net6.0-windows10.0.22000
- No dependencies.
-
net7.0-windows10.0.22000
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on Dubya.WindowsMediaController:
Repository | Stars |
---|---|
VRCWizard/TTS-Voice-Wizard
Speech to Text to Speech. Song now playing. Sends text as OSC messages to VRChat to display on avatar. (STTTS) (Speech to TTS) (VRC STT System) (VTuber TTS)
|
|
unchihugo/FluentFlyout
A simple and modern audio flyout for Windows 10/11, built with Fluent 2 Design principles.
|
|
BoiHanny/vrcosc-magicchatbox
The ultimate companion, whether you're on desktop or in VR, we've got you covered with our handy integrations in a compact and modern UI
|
- Added `StartAsync` method
- Added ability to get information on Focused Sessions.
- Added `ForceUpdate` to help alleviate bug https://github.com/DubyaDude/WindowsMediaController/issues/6
- Added NET 7 Build