Author Topic: Windows 10 Media Control Overlay  (Read 61772 times)

Nokiaman

  • Jr. Member
  • **
  • Posts: 63
The whole problem is because of the media control "feature" that if you press a keyboard media key, the media control also simulates a click on its buttons. And the plugin defines the appropriate action for the buttons. So everything is executed two times - one from media control buttons callback and one from music bee global hotkey.

So here is a fixed plugin for everyone who wants to have working media control buttons and working global hotkeys:
http://www.mediafire.com/file/7fdiewd2r3df62i/mb_MediaControl.zip/file

The fix uses a keyboard key press hook that watches for keyboard media key presses and saves the time of the last press. And if last press is less than 1500 milliseconds ago the media control button press is ignored.

For everyone who doesn't trust me, here is the source to see what is done and compile it yourself:
http://www.mediafire.com/file/hfrflurmkonsv8f/MediaControlSource.zip/file

Thank you so much!

PlumBlossom

  • Newbie
  • *
  • Posts: 11
Hello everyone!
I recently reset my laptop and reinstalled Windows and everything related. I downloaded the patched Windows 10 Media Overlay plugin and it works perfectly. The only thing I noticed is that the overlay block thing lingers on the screen for a bit before it fades away. It used to fade away much sooner when I had it before. It's really not too big of a deal because, like I said, the plugin works perfectly but I was wondering if there was a way to adjust it? Thanks!

literaldehyde

  • Newbie
  • *
  • Posts: 8
The whole problem is because of the media control "feature" that if you press a keyboard media key, the media control also simulates a click on its buttons. And the plugin defines the appropriate action for the buttons. So everything is executed two times - one from media control buttons callback and one from music bee global hotkey.

So here is a fixed plugin for everyone who wants to have working media control buttons and working global hotkeys:
http://www.mediafire.com/file/7fdiewd2r3df62i/mb_MediaControl.zip/file

The fix uses a keyboard key press hook that watches for keyboard media key presses and saves the time of the last press. And if last press is less than 1500 milliseconds ago the media control button press is ignored.

For everyone who doesn't trust me, here is the source to see what is done and compile it yourself:
http://www.mediafire.com/file/hfrflurmkonsv8f/MediaControlSource.zip/file

I have the bug where the base plugin plays tracks over each other, but this version of the plugin just completely disables media controls for me. Using 3.4.8033.

phred

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 9299
Using 3.4.8033.
If you're not using the Store version, try using the latest 3.5 from the first forum topic. If you're on the Store version there's nothing you can do until a new Store version is released.
Download the latest MusicBee v3.5 or 3.6 patch from here.
Unzip into your MusicBee directory and overwrite existing files.

----------
The FAQ
The Wiki
Posting screenshots is here
Searching the forum with Google is  here

literaldehyde

  • Newbie
  • *
  • Posts: 8
Using 3.4.8033.
If you're not using the Store version, try using the latest 3.5 from the first forum topic. If you're on the Store version there's nothing you can do until a new Store version is released.

I've updated to 3.5 and it hasn't changed anything. But I believe I've fixed the problem for myself.

I forgot to mention that because my laptop doesn't have dedicated media control buttons, I use an AutoHotkey script to rebind Ctrl+Shift+Left to Media_Prev, Ctrl+Shift+Right to Media_Right, and Ctrl+Shift+/ to Media_Play_Pause. I believe these AHK hotkeys send simulated media control presses, but aren't real buttons so alexdo's fix wasn't actually necessary for me. I only thought I needed it because I gave myself the double register bug by having the MusicBee multimedia global hotkeys set to the virtual media control buttons because I must have had the script running when I set them. This caused both MusicBee and Autohotkey to send media control commands simultaneously, instead of MusicBee + keyboard button conflicts other people were having.

I fixed it by changing the MusicBee multimedia global hotkeys to Ctrl+Shift+Left, Right, etc. while the AHK script was disabled. And now after reenabling it everything seems to be working fine including the overlay using the original version of the plugin. Only minor gripe is that as others have reported, audio needs to be played directly through the MusicBee window once after it starts up before the hotkeys begin to register. I noticed the Spotify app doesn't have that problem so I imagine there's a potential fix but who knows? Media Controls do conflict with other media players like Spotify, but that's not a problem for me because I've never needed to have both open at the same time.

Cheers!
Last Edit: February 14, 2023, 01:09:27 AM by literaldehyde

froschfinger

  • Newbie
  • *
  • Posts: 11
So far, this is working really well with the fixed version for the media keys from here. On Windows 11, this also intends to show the duration and track position a song is at, only it shows its length as 0:00 and as 100% played, no matter at what position the playback actually is, so the duration functionality doesn't seem to work. Did anybody ever solve this?
On top of it, this would be even sweeter if it showed up each time a new track is playing, just like the internal playback toast notification. I guess one can't have it all…

CharlieJiang

  • Newbie
  • *
  • Posts: 17
I've noticed some minor issues in alexdo's version:

1. I didn't register global media keys in MusicBee, so there's no actually double register issue for me. Therefore, the fix against double registration directly disabled my media keys.
2. The display isn't updated in time. When I click the Next track button in the overlay, the display isn't updated until it appears again.
3. The player and the overlay may get confused and lag if I spam-click the buttons in the overlay.

Therefore, I wrote a small fixed version for these 3 issues. Note that I disabled alexdo's fix for the double register problem, but you may need it! If that's the case, at the Line 29 in the `MediaControl.cs`, replace "0" to "2000", and recompile.

Here's the code and DLL files (I didn't upload this to GitHub because I don't know what's the open-source license):

https://1drv.ms/f/s!AicHZ6DLvCtXgYhCqD050XH_TeJF8Q?e=SDaFnQ

The key is to call `SetDisplayValues` and `SetPlayerState` right after any operation is done, and before calling `Player_PlayPause`, check if we really need to do that by calling `Player_GetPlayState` (When the player is paused, and the user issued a Pause command may be due to lag in UI update, you wouldn't want `Player_PlayPause` to be called because it actually starts the playback).

Several things to note:

1. Direct dependency on UWP DLLs is replaced to NuGet package `Microsoft.Windows.SDK.Contracts`, which handles the references to SMTC classes.
2. packages.config migrated to PackageReference.
3. Fody is used to weave global mouse key hook DLL into the final plugin DLL.
4. .NET Framework version is changed to 4.8.
5. The compiler complains that `BackgroundMediaPlayer` is obsolete, but I didn't find a better way to obtain `SystemMediaTransportControls` object in a desktop (non-UWP) app - advice needed!
6. @froschfinger It's certainly doable via `SystemMediaTransportControlsTimelineProperties` in the SMTC feature. However, I'm now using Windows 10 instead of Windows 11, so I don't have the chance to test such a feature, sorry...

It should be easier to compile this codebase than the original version due to the first 3 changes above. Notably, I expect that the compiler won't complain about the missing reference to UWP namespaces.
宇宙に始まりはあるが、終わりはない。 ---無限

froschfinger

  • Newbie
  • *
  • Posts: 11
Hey Charlie,

thanks for your new version. In fact, that was a good tip: Disabling the global media keys. I didn't need to delete them, I just unticked them to be global. That also solved the problem that when another app is having media playback, using the media keys on my keyboard toggled playback, so when one source stopped, the other one started playing (like YouTube and Musicbee). So as it stands, I won't need to recompile your version, so thanks a lot for the bug-fix version! If you at any point will be able to test the plugin with Windows 11, a fix for the progress bar and time display will come in handy. So far I'm happy I'm backing to having an overlay showing what song is playing or paused ;) .

bcrod

  • Newbie
  • *
  • Posts: 2
The overlay isn't update anymore when music is changed. Using Win 11 (last update in 01/07/2023)

bcrod

  • Newbie
  • *
  • Posts: 2
The overlay isn't update anymore when music is changed. Using Win 11 (last update in 01/07/2023)

Forget it. Just reinstall and work again.

HenryPDT

  • Newbie
  • *
  • Posts: 1
I improved on @CharlieJiang by fixing some broken/missing SMTC features such as Shuffle, Repeat and Timeline Info/Control to work with ModernFlyouts and other programs that read those SMTC information. This should work perfectly on Windows 11

DLL and source code can be found on:
https://github.com/HenryPDT/mb_MediaControl
Last Edit: January 27, 2024, 03:35:13 AM by HenryPDT