dweymouth / supersonic

A lightweight and full-featured cross-platform desktop client for self-hosted music servers
GNU General Public License v3.0
856 stars 42 forks source link

Media Key support on Windows #56

Open vbabiy opened 1 year ago

vbabiy commented 1 year ago

Are you planning on adding media key support?

dweymouth commented 1 year ago

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!

sentriz commented 1 year ago

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

at least on linux

dweymouth commented 1 year ago

Related: #75

dusnm commented 1 year ago

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.

vbabiy commented 1 year ago

MPRIS working great on linux (arch).

Great work!

bvarick commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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!

selexin commented 10 months ago

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

Love your work @dweymouth

dweymouth commented 10 months ago

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 commented 7 months ago

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 commented 7 months ago

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

dweymouth commented 7 months ago

Hmm, it seems like we could adapt Tauon Music Box's idea to access these APIs: https://github.com/Taiko2k/TauonMusicBox/commit/67425769e2d667ee206e511f819704b6bc68cb93#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 commented 6 months ago

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
ecker00 commented 1 month ago

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

dweymouth commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

I'd love this!

kernal64 commented 16 hours ago

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 commented 9 hours ago

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: https://github.com/dweymouth/supersonic/pull/403