Sinono3 / souvlaki

A cross-platform library for handling OS media controls and metadata.
MIT License
80 stars 15 forks source link

Linux: Volume control #36

Closed apprehensions closed 9 months ago

apprehensions commented 1 year ago

Currently as of latest commit f1690340d891616408406273b6f5d1ece1e82fbe at the time of this issue:

https://github.com/Sinono3/souvlaki/blob/f1690340d891616408406273b6f5d1ece1e82fbe/src/platform/mpris/zbus.rs#L308-L311

It seems that volume requests are simply not handled and is simply a stub function(?)

When is this feature going to be implemented and picked up by MPRIS requests?

Thanks.

Sinono3 commented 1 year ago

I'll work on it this week, thanks for pointing it out!

Sinono3 commented 1 year ago

Got something working. Check out the volume branch. Can you test it out with your program and check if everything works?

Sinono3 commented 1 year ago

Also, something I fear with this update is that MediaControlEvent is no longer Eq, maybe that will introduce a breaking change somewhere? I don't know, what do you think?

apprehensions commented 1 year ago

Eq? What?

what do you think?

Idk either, I have no clue about the MPRIS specification.

Also thanks! How can I test it with my program though? What can I change in the Cargo.toml files?

Sinono3 commented 1 year ago

Eq? What?

The MediaControlEvent enum previously implemented the Eq trait. Since now there is an float inside it, it can no longer implement Eq. I just wonder if any programs using this library will be affected by that, but I don't think it's a big deal.

What can I change in the Cargo.toml files?

Change your current line importing souvlaki to this:

souvlaki = { git = "https://github.com/Sinono3/souvlaki", branch = "volume" }

Then of course, implement the handling of the "SetVolume" event and also use the set_volume method whenever the volume is changed internally, to maintain consistency.

thewh1teagle commented 11 months ago

I would like to use volume control on MacOS too, does it already support it?

https://stackoverflow.com/questions/11045814/emulate-media-key-press-on-mac

Sinono3 commented 11 months ago

It was only implemented on Linux. I can't implement it for MacOS since I don't have access to an Apple device :cry: But this reminds me that the volume branch was never merged. @apprehensions, did you get around to using it? Did you find the behavior of volume control to be stable?

apprehensions commented 11 months ago

@aome510

Drigster commented 10 months ago

Any updates, will it be released to main branch?

aome510 commented 10 months ago

@aome510

I can't really test volume change on Linux because I don't have a Linux device

Sinono3 commented 10 months ago

To give an update on this. I've been working on a refactor of the library which will bring in a bunch of fixes as well as add missing features such as this one. Volume is already working on my machine.

aome510 commented 10 months ago

Great! Thanks @Sinono3. Look forward to the new changes

aome510 commented 10 months ago

@apprehensions in case you want to test volume control with spotify_player, you can checkout https://github.com/aome510/spotify-player/tree/test-volume

diff --git a/Cargo.lock b/Cargo.lock
index 54b9060..23a78d9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4106,9 +4106,8 @@ dependencies = [

 [[package]]
 name = "souvlaki"
-version = "0.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "951a075f224d8c87bb62a08c9c27a373fd6d453407e89cae00a25e2eac74ef51"
+version = "0.6.0"
+source = "git+https://github.com/Sinono3/souvlaki?branch=volume#0f8e6740b262958408ddc901220c4613b3f517ca"
 dependencies = [
  "block",
  "cocoa",
diff --git a/spotify_player/Cargo.toml b/spotify_player/Cargo.toml
index f5994cc..988d430 100644
--- a/spotify_player/Cargo.toml
+++ b/spotify_player/Cargo.toml
@@ -35,7 +35,7 @@ tracing = "0.1.40"
 tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
 lyric_finder = { version = "0.1.4", path = "../lyric_finder" , optional = true }
 backtrace = "0.3.69"
-souvlaki = { version = "0.6.1", optional = true }
+souvlaki = { git = "https://github.com/Sinono3/souvlaki", branch = "volume", optional = true }
 winit = { version = "0.29.4", optional = true }
 viuer = { version = "0.7.1", optional = true }
 image = { version = "0.24.7", optional = true }
diff --git a/spotify_player/src/media_control.rs b/spotify_player/src/media_control.rs
index 133e966..6bc5367 100644
--- a/spotify_player/src/media_control.rs
+++ b/spotify_player/src/media_control.rs
@@ -109,6 +109,11 @@ pub fn start_event_watcher(
                     .send(ClientRequest::Player(PlayerRequest::PreviousTrack))
                     .unwrap_or_default();
             }
+            MediaControlEvent::SetVolume(volume) => client_pub
+                .send(ClientRequest::Player(PlayerRequest::Volume(
+                    (volume * 100.0) as u8,
+                )))
+                .unwrap_or_default(),
             _ => {}
         }
     })?;
thewh1teagle commented 9 months ago

@Sinono3 Does it support volume on macos now?

Sinono3 commented 9 months ago

Just pushed version 0.7 which should have volume control for Linux.

Does it support volume on macos now?

No, sorry. I plan on buying a Mac soon. There won't be support until then or until someone else implements it. I'll create other issues for the other OSes.

LucasFA commented 9 months ago

I am happy to report that testing with the following command:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify_player /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set string:'org.mpris.MediaPlayer2.Player' string:'Volume' variant:double:0.4

Reveals that, yes the test_volume branch of spotify_player works as intended with souvlaki. Souvlaki 0.7.0 also works.

Sinono3 commented 9 months ago

@LucasFA Thanks for testing! :slightly_smiling_face: