volume_unix.go 1.2 KB

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