DubyaDude / WindowsMediaController

Allows 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))
https://nuget.org/packages/Dubya.WindowsMediaController
MIT License
129 stars 9 forks source link

How to use this wrapper. #1

Closed cblackler19 closed 2 years ago

cblackler19 commented 3 years ago

There is no information regarding how to use this wrapper. Could you update the readme please as I'd love to use this.

DubyaDude commented 3 years ago

There is an example project, but sure I'll do so once I'm back from the holidays :)

2hands10fingers commented 3 years ago

Since it's after the holidays, could you elaborate on this project use? :)

benehmb commented 3 years ago

If you want to use the Example project, you just can checkout the repository and then set the "Test"-project as default. To use it in your own code, you can add your methods to be triggered, when something happened. There are 4 Events, that can be used: OnNewSource, OnRemovedSource, OnPlaybackStateChangedand OnSongChanged. Just write your methods and then add them in your Main to be triggered, when something happens: In main: MediaManager.OnPlaybackStateChanged += MediaManager_OnPlaybackStateChanged;, and my MediaManager_OnPlaybackStateChanged looks like this:

        /// <summary>
        /// Update the Playback-State according to passed arguments
        /// </summary>
        /// <param name="sender">Class that called method</param>
        /// <param name="args">Infos of playback state like is playing or shuffle</param>
        private void MediaManager_OnPlaybackStateChanged(MediaManager.MediaSession sender, GlobalSystemMediaTransportControlsSessionPlaybackInfo args)
        {
            WriteLineColor($"{sender.ControlSession.SourceAppUserModelId} is now {args.PlaybackStatus}", ConsoleColor.Magenta);
            IsCurrentlyPlaying = args.PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing ? true : false;
        }

Your methods have to have a session and some args. What those args are, depends on the event that is triggered, but Visual Studio can generate it for you. If you have your method, you can just have a look at the depended args-object to see what you can do with it. For Example the Object of my MediaManager_OnPlaybackStateChanged-method is an GlobalSystemMediaTransportControlsSessionPlaybackInfo and it has the useful attributes IsShuffleActive, PlaybackRate, PlaybackStatus, PlaybackType and AutoRepeatMode, which are pretty self explaining.

WTFBlaze commented 3 years ago

@benehmb how would I be able to use this in a .NET Library? or would I ONLY be able to use this in a console application?

Only reason I ask is cause I saw somewhere that UWP doesn't support .NET Libraries to use them.

benehmb commented 3 years ago

@WTFBlaze I am not sure, if i understand you right, but if I do so: You can just make your own solution with whatever project you want. Then right click on your solution add > add existing project. Then you need to select the "WindowsMediaController"-Project in your explorer. After it is in your solution, you need to add a reference: Right click on references (inside of your Project) > add reference... > Projects > Solution. Then check the Checkbox for "WindowsMediaController" and you can use it in your Project. I used in a WPF-Application (MediaControllUI) and it worked fine.

Edit: I translated most of the Therms in English, so maybe some steps have similar names

WTFBlaze commented 3 years ago

I appreciate the response. I'll give it a shot.

DubyaDude commented 2 years ago

I know this is well close to a year, and I'm sorry for the delay, but I have done an overhaul with the project which includes a quick start in the ReadMe and includes a new sample to better see usage.