Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Key support on Windows #56

Open
vbabiy opened this issue Mar 2, 2023 · 24 comments
Open

Media Key support on Windows #56

vbabiy opened this issue Mar 2, 2023 · 24 comments
Labels
enhancement New feature or request help wanted Extra attention is needed os:windows

Comments

@vbabiy
Copy link

vbabiy commented Mar 2, 2023

Are you planning on adding media key support?

@dweymouth
Copy link
Owner

dweymouth commented Mar 2, 2023

Edit 10/21/23: repurposing this issue for Windows media key integration since that's the last platform left

Media key support will need to be implemented using the media APIs of each platform. Tracking the completion of each platorm here:


Old invalid info, for historical context

Yes, I definitely would like to add media key support. There is no builtin API in the Fyne toolkit that this project is using for this, however. So I will either A) need to add a media key API to my Fyne fork, or B) find another 3rd party package that can provide media key events. If anyone knows of a 3rd party Go package for media keys, or how to scan for media key events in GLFW (so I can add it to the Fyne fork), please let me know!

@dweymouth dweymouth added enhancement New feature or request help wanted Extra attention is needed labels Mar 2, 2023
@dweymouth dweymouth pinned this issue Mar 3, 2023
@sentriz
Copy link

sentriz commented Mar 6, 2023

i think you need MPRIS https://wiki.archlinux.org/title/MPRIS

at least on linux

@dweymouth
Copy link
Owner

Related: #75

@dusnm dusnm mentioned this issue Apr 18, 2023
@dusnm
Copy link
Contributor

dusnm commented Apr 18, 2023

This is heavily platform dependent. Unix-like systems that implement free desktop standards like D-Bus (this would exclude MacOS) handle media keys through MPRIS. This also provides media controls for desktop environments like Gnome.

I doubt there is a clean way to make this feature cross-platform without implementing a solution for each platform separately.

@dweymouth dweymouth unpinned this issue Jul 15, 2023
@vbabiy
Copy link
Author

vbabiy commented Jul 26, 2023

MPRIS working great on linux (arch).

Great work!

@bvarick
Copy link

bvarick commented Aug 4, 2023

I'm struggling to get the media keys to work on Linux with a flatpak install. I think the permissions are off, but I'm not sure. Its currently listed as owning "org.mpris.MediaPlayer2.Supersonic". I think the ID is "dweymouth.supersonic", so maybe it should match?

@dweymouth
Copy link
Owner

I'm struggling to get the media keys to work on Linux with a flatpak install. I think the permissions are off, but I'm not sure. Its currently listed as owning "org.mpris.MediaPlayer2.Supersonic". I think the ID is "dweymouth.supersonic", so maybe it should match?

You may need to force-update the Flatpak. There was a recently fixed issue with Flatpak MPRIS permissions and the Flatpak manifest was updated but the app version number has not been bumped. See #226

@bvarick
Copy link

bvarick commented Aug 6, 2023

You may need to force-update the Flatpak. There was a recently fixed issue with Flatpak MPRIS permissions and the Flatpak manifest was updated but the app version number has not been bumped. See #226

That worked great, thanks!

@dweymouth dweymouth changed the title Media Key support Media Key support on Windows Oct 21, 2023
@selexin
Copy link

selexin commented Nov 15, 2023

Hey, how's progress going on the Windows Media Key support? Reckon we might see it in 0.90? 🙏

Love your work @dweymouth

@dweymouth
Copy link
Owner

Maybe.. definitely if you know anyone who knows WinAPI C/C++ development and can refer them over here :) Mac media key support was contributed by someone familiar with MacOS dev

@dweymouth
Copy link
Owner

Did a little more digging, and it seems like it may be difficult to get this working on Windows. See this issue here for discussion - but it seems the SystemMediaTransportControls APIs are a bit problematic to use for non-UWP apps, and especially apps built with a cross platform toolkit that never exposes a HWND directly.

@selexin
Copy link

selexin commented Jan 31, 2024

Thanks for the update @dweymouth fingers crossed they eventually make it easier to include windows media key integration. Still loving Supersonic.

@dweymouth
Copy link
Owner

Hmm, it seems like we could adapt Tauon Music Box's idea to access these APIs: Taiko2k/Tauon@6742576#diff-6b63f857d89b9e3a0dbd1cc014f89df23bf20d881fa07638c382044f6c73bf08

They compile a DLL that creates a dummy hidden application window so it can have access to those APIs. Maybe someone with more Win32 dev experience could give this approach a try

@nchietala
Copy link

For those of us on windows this AutoHotKey script will enable play/pause functionality while we wait for an update:

Media_Play_Pause::
    WinGet, targetWindow, ID, ahk_exe Supersonic.exe
    
    if (targetWindow) {
        ControlSend,, {Space}, ahk_id %targetWindow%
    }
    else {
        Run, "C:\Program Files\SuperSonic\Supersonic.exe"
        WinWait, ahk_exe Supersonic.exe,, 10
        WinGet, TargetWindow, ID, ahk_exe Supersonic.exe

        if (TargetWindow) {
            ControlSend,, {Space}, ahk_id %TargetWindow%

            WinClose, ahk_id %TargetWindow%
            ; WinMinimize, ahk_id %TargetWindow%
            ; This assumes that you've set your window to close to the system tray, move the comment ";" to the WinClose line if that is not the case.
        }
    }
return

@dweymouth dweymouth pinned this issue Jun 5, 2024
@ecker00
Copy link

ecker00 commented Aug 8, 2024

Doesn't seem to work for me in KDE (Thumbleweed), guess MPRIS is for Gnome / GTK? (using flatpak version 0.12.0)

@dweymouth
Copy link
Owner

Doesn't seem to work for me in KDE (Thumbleweed), guess MPRIS is for Gnome / GTK? (using flatpak version 0.12.0)

Can you try a direct installation (either build from source or install the release build, if your libmpv is packaged at the same location as on Ubuntu/Debian) instead of Flatpak? That would help see if the issue is in the Flatpak sandboxing or in the app itself

@dweymouth
Copy link
Owner

dweymouth commented Aug 8, 2024

For those of us on windows this AutoHotKey script will enable play/pause functionality while we wait for an update:

Just wanted to add for the Windows users, the AutoHotKey script above could be modified now that Supersonic supports command-line control to running "C:\Program Files\Supersonic\supersonic.exe --play-pause", no need to get the window and send a space bar keystroke to it. This should work more reliably, including when the window is closed to system tray

@EmmaKnijn
Copy link

I'd love this!

@kernal64
Copy link

kernal64 commented Sep 19, 2024

For those of us on windows this AutoHotKey script will enable play/pause functionality while we wait for an update:

Just wanted to add for the Windows users, the AutoHotKey script above could be modified now that Supersonic supports command-line control to running "C:\Program Files\Supersonic\supersonic.exe --play-pause", no need to get the window and send a space bar keystroke to it. This should work more reliably, including when the window is closed to system tray

That's indeed helpful. I discovered, that supersonic also supports command-line parameters --play, --pause, --previous, --next and --volume nn. Is there --volume-up and --volume-down planned? Please provide a list with all valid parameters. Unfortunately --help does nothing - at least on Windows.

I just switched from strawberry to supersonic. Great work!

@dweymouth
Copy link
Owner

Please provide a list with all valid parameters. Unfortunately --help does nothing - at least on Windows.

The reason --help does nothing on Windows is that Windows GUI apps don't get a console attached so there's nowhere to print to. Blame Microsoft ;)

But the output of supersonic --help was attached to this PR description: #403

@FibreTTP
Copy link

FibreTTP commented Sep 27, 2024

A PR was merged back at the end of July adding support for controlling playback in mpv through the SMTC API, here:

This feature hit mpv's stable with the update a few days ago.

The feature is controlled with a new configuration option called media-controls:

(Windows only) Enable integration of media control interface SystemMediaTransportControls. If set to player, only the player will use the controls. Setting it to yes will also enable the controls for libmpv integrations. (default: player)

In standalone mpv, the feature works perfectly. Playing, pausing, and stopping, as well as skipping forward and backward work as expected, in the foreground or background.

Adding m.SetOptionString("media-controls", "yes") to the init. options in backend/player/mpv/player.go, allows this feature to work in Supersonic as well.

Play/pause and stop functionally works fine (see below), but unfortunately skipping backwards is quite buggy. Skipping backwards doesn't do anything unless you have skipped forwards at least once, at which point skipping backwards plays the audio of the previous song, but the UI shows the next song playing.

Playing and pausing messes with the UI, however. The play/pause symbol doesn't update when controlling with SMTC, and the playback progress bar doesn't resume moving when you pause the track with the UI, and play it again with SMTC. Subsequently, if the track ends with the play/pause symbol and playback bar "stuck", when the next track begins playing, both the symbol and the bar will remain stuck (although everything else in the UI changes). Stopping works normally.

Anyway, in order to even have access to the feature, you must use a libmpv built on any commit since the PR was merged. I simply used shinchiro's build to test: https://github.com/shinchiro/mpv-winbuild-cmake/releases/tag/20240926.

(this is a good time to update the libmpv packaged in releases)

@dweymouth
Copy link
Owner

Play/pause and stop functionally works fine (see below), but unfortunately skipping backwards is quite buggy. Skipping backwards doesn't do anything unless you have skipped forwards at least once, at which point skipping backwards plays the audio of the previous song, but the UI shows the next song playing.

Yeah, I'm not surprised this doesn't work well - Supersonic relies on the fact that it is controlling MPV. It actually only loads the current and next song into MPV's play queue for performance (so queuing a 10,000-track playlist is just as instantaneous as queuing 10 tracks), and in the future I'm hoping to support DLNA casting, Subsonic jukebox mode, or other players that aren't MPV. This is why I've been hoping someone familiar with Windows development can help make a DLL that Supersonic can load to interface with SMTC directly. I'm unlikely to pursue using MPV's SMTC as a permanent solution but it is nice in the meantime

@TheStakman
Copy link

TheStakman commented Sep 27, 2024

Doesn't seem to work for me in KDE (Thumbleweed), guess MPRIS is for Gnome / GTK? (using flatpak version 0.12.0)

Can you try a direct installation (either build from source or install the release build, if your libmpv is packaged at the same location as on Ubuntu/Debian) instead of Flatpak? That would help see if the issue is in the Flatpak sandboxing or in the app itself

I haven't tried a direct install yet, but the other day I noticed the media keys not working on Linux Mint via flatpak. So I updated my apt and upgraded packages. Then for some reason the media keys were working. The next day, after a reboot, media keys stopped working. Not sure if that gives you any ideas as far as the flatpak version is concerned. Also, I got a flatpak update for Supersonic today, (which didn't help) but that's weird since the last release of Supersonic was last month?

EDIT: Media keys work when building from source, at least originally. Then I figured I'd test installing from https://github.com/dweymouth/supersonic/releases/download/v0.13.1/Supersonic-0.13.1-linux-x64-libmpv2.tar.xz but the media keys didn't work. Then I tried building from source again, but the media keys didn't work this time. I'm starting to wonder if the issue has something to do with Netflix.

@TheStakman
Copy link

Okay, so after many reboots (thanks NVME drive) I've found out a couple things as far as Linux installations go:

OS: LMDE faye 6 x86_64
Kernel: Linux 6.1.0-12-amd64
DE: Cinnamon 6.2.9
Shell: bash 5.2.15

Flatpak Version

  • If you open Supersonic first thing after reboot and hit the play media key, I get a big don't sign on my desktop as Mint LMDE thinks there's no media. This seems to be consistent every time I do it thins way.
  • If you open Supersonic first thing after reboot and click the play button in the GUI of Supersonic with your mouse, then use the media keys it works.

Libmpv2 Install

  • If you open Supersonic first thing after reboot and only use the media keys it works just fine, or if you click the play button in the GUI then use the media keys.

  • I opened Netflix via Firefox which also uses media keys. While Netflix is up (not even currently playing video), the media keys do not work with Supersonic and only with Netflix, even if I click the play button in the GUI first. After closing Firefox (or just the Netflix tab), the media keys switch back to Supersonic.

    Inversely, if I have media keys working with Supersonic and music playing, then pull up Netflix, the media keys are stuck to Supersonic which is fine. If I close Supersonic the media keys switch over to Netflix.

Build From Source

  • Seems to be the same deal as the Libmpv2 install.

Side Note

  • Not that it will ever matter in normal use, but may help in identifying the issue.

    If you have media keys currently working on one Instance of Supersonic no matter the install method, then open a different one. The media keys will only work for the first one you opened and will not switch over to any other instance of Supersonic. Even if you close out the first one with working media keys.

    Another weird thing is after I closed the working one, then reopened. The media keys sometimes would work, then close and reopen click on play in the GUI then the media keys worked. Then close and reopen, then no matter what I did media keys would not work.

Conclusion

  • While it is annoying that media keys don't work when Netflix is up (which is basically all the time as it doesn't matter if it's actively playing video or not) Something is definitely off when it comes to the Flatpak version compared to the others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed os:windows
Projects
None yet
Development

No branches or pull requests