From 76809726d5b712099ff705bb8bdaeef6583df4db Mon Sep 17 00:00:00 2001 From: razorkitty Date: Sat, 19 Nov 2022 21:30:54 +0000 Subject: [PATCH 1/2] replace pactl based volume control with mpris based volume control methods --- pkg/player/pactl.go | 16 ---------------- pkg/player/player.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 16 deletions(-) delete mode 100644 pkg/player/pactl.go diff --git a/pkg/player/pactl.go b/pkg/player/pactl.go deleted file mode 100644 index 3dc3441..0000000 --- a/pkg/player/pactl.go +++ /dev/null @@ -1,16 +0,0 @@ -package player - -import ( - "fmt" - "os/exec" -) - -// VolUp uses pactl to increase the volume of the default sink -func VolUp(percent uint) error { - return exec.Command("pactl", "set-sink-volume", "@DEFAULT_SINK@", fmt.Sprintf("+%d%%", percent)).Run() -} - -// VolDown uses pactl to decrease the volume of the default sink -func VolDown(percent uint) error { - return exec.Command("pactl", "set-sink-volume", "@DEFAULT_SINK@", fmt.Sprintf("-%d%%", percent)).Run() -} diff --git a/pkg/player/player.go b/pkg/player/player.go index 6f3e202..5358a80 100644 --- a/pkg/player/player.go +++ b/pkg/player/player.go @@ -107,6 +107,46 @@ func Prev() error { return nil } +func VolUp(percent uint) error { + + player, err := getPlayerObj() + if err != nil { + return err + } + if player != nil { + currentVal, err := player.GetProperty("org.mpris.MediaPlayer2.Player.Volume") + if err != nil { + return err + } + newVal := currentVal.Value().(float64) + (float64(percent) / 100) + err = player.SetProperty("org.mpris.MediaPlayer2.Player.Volume", newVal) + if err != nil { + return err + } + } + return nil +} + +func VolDown(percent uint) error { + + player, err := getPlayerObj() + if err != nil { + return err + } + if player != nil { + currentVal, err := player.GetProperty("org.mpris.MediaPlayer2.Player.Volume") + if err != nil { + return err + } + newVal := currentVal.Value().(float64) - (float64(percent) / 100) + err = player.SetProperty("org.mpris.MediaPlayer2.Player.Volume", newVal) + if err != nil { + return err + } + } + return nil +} + type ChangeType int const ( From 5fb5cf4b928bb0962a4c17fd94ea63eb8a98139b Mon Sep 17 00:00:00 2001 From: razorkitty Date: Sat, 19 Nov 2022 22:43:03 +0000 Subject: [PATCH 2/2] removed pulseaudio-utils and libpulse dependencies --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 37210a7..3494639 100644 --- a/README.md +++ b/README.md @@ -15,24 +15,24 @@ This library's import path is `go.arsenm.dev/infinitime`. ### Dependencies -This library requires `dbus`, `bluez`, and `pactl` to function. These allow the library to use bluetooth, control media, control volume, etc. +This library requires `dbus`, and `bluez` to function. These allow the library to use bluetooth, control media, control volume, etc. #### Arch ```shell -sudo pacman -S dbus bluez libpulse --needed +sudo pacman -S dbus bluez --needed ``` #### Debian/Ubuntu ```shell -sudo apt install dbus bluez pulseaudio-utils +sudo apt install dbus bluez ``` #### Fedora ```shell -sudo dnf install dbus bluez pulseaudio-utils +sudo dnf install dbus bluez ``` --- @@ -53,4 +53,4 @@ This library currently supports the following features: ### Mentions -The DFU process used in this library was created with the help of [siglo](https://github.com/alexr4535/siglo)'s source code. Specifically, this file: [ble_dfu.py](https://github.com/alexr4535/siglo/blob/main/src/ble_dfu.py) \ No newline at end of file +The DFU process used in this library was created with the help of [siglo](https://github.com/alexr4535/siglo)'s source code. Specifically, this file: [ble_dfu.py](https://github.com/alexr4535/siglo/blob/main/src/ble_dfu.py)