volume_unix.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //go:build !windows
  2. // +build !windows
  3. /*
  4. * Copied from https://github.com/itchyny/volume-go, MIT License
  5. */
  6. package Sound
  7. import (
  8. "errors"
  9. //"fmt"
  10. //"os"
  11. //"os/exec"
  12. //"strings"
  13. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  14. )
  15. // GetVolume returns the current volume (0 to 100).
  16. func GetVolume() (int, error) {
  17. out, err := UI.ExecCmd(getVolumeCmd())
  18. if err != nil {
  19. return 0, err
  20. }
  21. return parseVolume(string(out))
  22. }
  23. // SetVolume sets the sound volume to the specified value.
  24. func SetVolume(volume int) error {
  25. if volume < 0 || 100 < volume {
  26. return errors.New("out of valid volume range")
  27. }
  28. _, err := UI.ExecCmd(setVolumeCmd(volume))
  29. return err
  30. }
  31. // IncreaseVolume increases (or decreases) the audio volume by the specified value.
  32. func IncreaseVolume(diff int) error {
  33. _, err := UI.ExecCmd(increaseVolumeCmd(diff))
  34. return err
  35. }
  36. // GetMuted returns the current muted status.
  37. func GetMuted() (bool, error) {
  38. out, err := UI.ExecCmd(getMutedCmd())
  39. if err != nil {
  40. return false, err
  41. }
  42. return parseMuted(string(out))
  43. }
  44. // Mute mutes the audio.
  45. func Mute() error {
  46. _, err := UI.ExecCmd(muteCmd())
  47. return err
  48. }
  49. // Unmute unmutes the audio.
  50. func Unmute() error {
  51. _, err := UI.ExecCmd(unmuteCmd())
  52. return err
  53. }