Home

Awesome

Windows Media Controller

NuGet

This repository provides a wrapper for developers to more easily get information from and interact with the Windows 10/11 OS media interface (Also referred to Windows System Media Transport Controls (SMTC)).

Windows 10 Media Interface

This allows for a better understanding and control of the Media Sessions and can have many different applications. Some features include:

Requirements

NET Framework:

For .NET Framework, I've seen people encountering issues with how the package gets imported. This is caused by using an older format of .NET projects (you can see the newer format being used in Sample.CMD). If you have this issue, add the package by adding this to the .csproj file. <br> (replacing '2.5.5' with the preferred NuGet version)

<ItemGroup>
  <PackageReference Include="Dubya.WindowsMediaController">
    <Version>2.5.5</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 net6.0 with desired .NET version)

<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>

How To Use

Initialization:

mediaManager = new MediaManager();

mediaManager.OnAnySessionOpened += MediaManager_OnAnySessionOpened;
mediaManager.OnAnySessionClosed += MediaManager_OnAnySessionClosed;
mediaManager.OnFocusedSessionChanged += MediaManager_OnFocusedSessionChanged;
mediaManager.OnAnyMediaPropertyChanged += MediaManager_OnAnyMediaPropertyChanged;
mediaManager.OnAnyPlaybackStateChanged += MediaManager_OnAnyPlaybackStateChanged;
mediaManager.OnAnyTimelinePropertyChanged += MediaManager_OnAnyTimelinePropertyChanged;

mediaManager.Start();
OR
await 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);
delegate void OnAnyTimelinePropertyChanged(MediaSession mediaSession, GlobalSystemMediaTransportControlsSessionTimelineProperties timelineProperties);

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);
delegate void OnTimelinePropertyChanged(MediaSession mediaSession, GlobalSystemMediaTransportControlsSessionTimelineProperties timelineProperties);

Getting Some Info:

Useful Microsoft Documentations:

Samples

Sample.CMD

Sample.UI

Credit