-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Comments
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
|
i think you need MPRIS https://wiki.archlinux.org/title/MPRIS at least on linux |
Related: #75 |
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. |
MPRIS working great on linux (arch). Great work! |
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 |
That worked great, thanks! |
Hey, how's progress going on the Windows Media Key support? Reckon we might see it in 0.90? 🙏 Love your work @dweymouth |
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 |
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. |
Thanks for the update @dweymouth fingers crossed they eventually make it easier to include windows media key integration. Still loving Supersonic. |
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 |
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 |
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 |
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 |
I'd love this! |
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! |
The reason But the output of |
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
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 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) |
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 |
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. |
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 Flatpak Version
Libmpv2 Install
Build From Source
Side Note
Conclusion
|
For SMTC it would be cool if the player reported the following information:
That way it could work flawlessly with Music Presence (https://github.com/ungive/discord-music-presence) to show a Discord status for the media that is being played with the player. Related: ungive/discord-music-presence#146 |
Good news! This is finally being worked on and I could benefit from any Windows users testing the build from Github Actions in the linked PR! Specifically anyone using ungive/discord-music-presence since the Windows UI control doesn't seem to show the play time in any way so I'm not sure the implementation is correct. |
You can test your implementation with this command line program I made some time ago that shows all the details reported by SMTC: https://github.com/ungive/media-session-dump There's a build in the releases. |
@dweymouth Testing this, I seem to be crashing as soon as playback starts, though I can sometimes hear a short moment of the beginning of the track. I believe the logs are normal, too (stable Supersonic prints the same logs):
|
@FibreTTP Which OS version are you on? It seems fine to me on Windows 11 from my (not super extensive) testing. Also did the track that was playing when it crashed have artwork? It sounds like a short moment of the beginning of the track before it crashes may point to problems with loading the album art into Windows's API, because that happens after loading the title/artist. |
@dweymouth I'm on Windows 11 too. You seem to have guessed it with the artwork: playing a track with cover art crashes Supersonic. I tested with multiple tracks without cover art, and it doesn't crash. |
Hmm, strange. I may have to back out the cover art support for SMTC unless someone else can look into it and debug the github.com/supersonic-app/smtc-dll implementation, I can't get it to crash on my end. (All my tracks have cover art and they all seemed to work and show the cover) |
Willing to help but don't know Github that much : how to acces the build ? I tried https://github.com/dweymouth/supersonic/actions/workflows/build-windows.yml which points to current release and I don't know where to access from the PR which might be this one #533 |
First simple test with [version 10.0.26100.2894], the keyboard at my office has a single play/pause media button and it works ! I'll do more testing and longtime testing at home. A question : could this evolution also lead to muting the music when a phone call is received ? |
No idea, sorry |
Whoa, well that's the problem. I have no idea why your cached image files are 0 bytes and I'm surprised Supersonic is able to show covers at all on your system! They are supposed to be 300x300px JPGs. What a mystery! What server do you use? |
It's also concerning that the SMTC APIs just crash when given a bad image. And I also didn't see any error code or any other way for the API to communicate an error instead of just crashing :(. I suppose I'll have to try to validate the image somehow beforehand, but first the mystery of why covers are being saved strangely for @FibreTTP. @CharlesDelorme was it able to show cover art in the OS media center for you without crashing? |
Haha, I use LMS. Yep, looking at the LMS logs, it seems like Supersonic is requesting a cover art with an ID in the format of Supersonic writes this filename directly to the filesystem, meaning on NTFS, the file will be called LMS log examples (auth parameters removed and URL decoded):
|
Good find! I'll have to call some path sanitizing function (maybe just hashing the ID from the server could be fine) and then it should work. And it's good that this was discovered because I assume Supersonic itself has probably been unable to read its own cover cache files with LMS this whole time (unless Go handles reading Alternate Data Streams -- I'd never even heard of them before) |
Covers are in C:\Users[user]\AppData\Local\supersonic\3855131a-b91d-4193-a373-d7cf014f202d\covers and are updated (server is Navidrome [0.54.3]). I had a hard way finding the "OS media center" but it simply showed when clicking on the network/sound/battery button on the task bar. I can confirm the cover is there too but the app is shown unknown ("Application inconnue" is french for "Unknow application") (when youtube player from a browser it says the browser name, when Foobar2000 is used, unknown). It also works clicking on the play/pause next/previous buttons in the media center |
Back home on windows 10 [version 10.0.19045.5247] with a Keyboard Corsair K55 pro XT. There are four keys : stop/previous/play|pause/next and all work. When the musique is stoped, the name of the app is correctly shown. I lost the play/pause key at a time (others were ok) but it came back. I guess this works :-) |
Have same results on Windows 10 19045.5371, Logitech G413 TKL SE keyboard media keys all working now, cover is displayed (Navidrome 0.54.4). Thank you very much, this was the only missing piece in this awesome app. |
Are you planning on adding media key support?
The text was updated successfully, but these errors were encountered: