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

Linux: Volume control #36

Closed
apprehensions opened this issue Feb 22, 2023 · 17 comments · Fixed by #42
Closed

Linux: Volume control #36

apprehensions opened this issue Feb 22, 2023 · 17 comments · Fixed by #42
Labels
enhancement New feature or request linux Issues related to MPRIS

Comments

@apprehensions
Copy link

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

#[dbus_interface(property)]
fn volume(&self) -> f64 {
1.0
}

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
Copy link
Owner

Sinono3 commented Mar 1, 2023

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

@Sinono3
Copy link
Owner

Sinono3 commented Mar 2, 2023

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

@Sinono3
Copy link
Owner

Sinono3 commented Mar 2, 2023

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
Copy link
Author

apprehensions commented Mar 2, 2023

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
Copy link
Owner

Sinono3 commented Mar 2, 2023

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
Copy link

thewh1teagle commented Nov 25, 2023

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
Copy link
Owner

Sinono3 commented Nov 27, 2023

It was only implemented on Linux. I can't implement it for MacOS since I don't have access to an Apple device 😢
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
Copy link
Author

@aome510

@Drigster
Copy link

Any updates, will it be released to main branch?

@aome510
Copy link

aome510 commented Dec 24, 2023

@aome510

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

@Sinono3
Copy link
Owner

Sinono3 commented Dec 24, 2023

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
Copy link

aome510 commented Dec 24, 2023

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

@aome510
Copy link

aome510 commented Dec 24, 2023

@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
Copy link

@Sinono3
Does it support volume on macos now?

@Sinono3 Sinono3 reopened this Jan 5, 2024
@Sinono3
Copy link
Owner

Sinono3 commented Jan 5, 2024

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.

@Sinono3 Sinono3 added enhancement New feature or request linux Issues related to MPRIS labels Jan 5, 2024
@Sinono3 Sinono3 changed the title Volume control Linux: Volume control Jan 5, 2024
@Sinono3 Sinono3 closed this as completed Jan 5, 2024
@LucasFA
Copy link
Contributor

LucasFA commented Jan 26, 2024

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
Copy link
Owner

Sinono3 commented Jan 28, 2024

@LucasFA Thanks for testing! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request linux Issues related to MPRIS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants