hrkfdn / ncspot

Cross-platform ncurses Spotify client written in Rust, inspired by ncmpc and the likes.
BSD 2-Clause "Simplified" License
4.94k stars 205 forks source link

Cross platform media control #703

Open rashil2000 opened 2 years ago

rashil2000 commented 2 years ago

Is your feature request related to a problem? Please describe. I see that media control on Linux has been implemented via MPRIS. It would be great to have this functionality on all platforms.

Describe the solution you'd like There's a crate - https://github.com/Sinono3/souvlaki - which abstracts away media control under a unified function. It not only supports Linux (via MPRIS), but also has full support for Windows and macOS.

Describe alternatives you've considered None

Additional context This is what a typical function looks like in souvlaki:

    controls
        .set_metadata(MediaMetadata {
            title: Some("When The Sun Hits"),
            album: Some("Souvlaki"),
            artist: Some("Slowdive"),
            duration: Some(Duration::from_secs_f64(4.0 * 60.0 + 50.0)),
            cover_url: Some("https://c.pxhere.com/photos/34/c1/souvlaki_authentic_greek_greek_food_mezes-497780.jpg!d"),
        })
        .unwrap();

See https://github.com/Sinono3/souvlaki/tree/master/examples for more examples.

jacksongoode commented 2 years ago

This would be fantastic! 👍

itytophile commented 2 years ago

I've investigated the problem. It seems to me that to have access to the Windows media controls we need to have a "handle to a window" (HWND). Unfortunately ncspot is a terminal app and I didn't find a way to get a handle that works with souvlaki. I've used GetConsoleWindow (which is deprecated) without success.

rashil2000 commented 2 years ago

Hmm, doesn't the example code there seem to be using a console application?

itytophile commented 2 years ago

To have a MediaControl instance (controls in your example) you have to provide a PlatformConfig that needs a HWND (https://docs.rs/souvlaki/latest/souvlaki/struct.MediaControls.html#method.new). On Windows it is required as you can see in souvlaki source code.

EDIT: In souvlaki repo it shows an example that uses winit to create a windows then get a handle from it. The other examples don't show how to get a handle from a console app unfortunately.

rashil2000 commented 2 years ago

Ah, I see...

jacksongoode commented 2 years ago

@itytophile Well getting it working for macOS/Linux systems would still be a win right?

This feels like such a needed feature for a media player app.

itytophile commented 2 years ago

@jacksongoode I already have media control on my linux desktop (GNOME) and I thought that the feature was available on macOS. I don't have an apple device to test that out.

jacksongoode commented 2 years ago

@jacksongoode I already have media control on my linux desktop (GNOME) and I thought that the feature was available on macOS. I don't have an apple device to test that out.

Huh, then the controls aren't exposed for macOS.

rashil2000 commented 2 years ago

MPRIS API is only available for Linux.

This issue request is for Windows and macOS support.

jacksongoode commented 1 year ago

Is this on the roadmap @hrkfdn? Global media keys on macOS would be really great.

jacksongoode commented 1 year ago

It seems souvlaki has support for zbus as a backend as well https://github.com/Sinono3/souvlaki#linux-backends-d-bus-and-zbus

sreekarchigurupati commented 1 year ago

Global media keys support would be great for MacOS. Would it also end up showing the album art here?

Screenshot 2023-05-31 at 3 38 36 PM
ptixed commented 12 months ago

I've investigated the problem. It seems to me that to have access to the Windows media controls we need to have a "handle to a window" (HWND). Unfortunately ncspot is a terminal app and I didn't find a way to get a handle that works with souvlaki. I've used GetConsoleWindow (which is deprecated) without success.

Couldn't you spawn an invisible window that would grab key events and pass them into ncspot?

jacksongoode commented 12 months ago

Couldn't you spawn an invisible window that would grab key events and pass them into ncspot?

That's how https://github.com/aome510/spotify-player/ approaches media controls.

ptixed commented 12 months ago

@jacksongoode Are you working on this? I was thinking of maybe picking this up as an excuse to learn rust.

jacksongoode commented 12 months ago

@ptixed No I'm not, I would go ahead and use that other project to guide you!