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

add Client.SetSinkMute() function #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (c *Client) SetVolume(volume float32) error {
return c.setSinkVolume(s.DefaultSink, cvolume{uint32(volume * 0xffff)})
}

// SetSinkVolume changes the current volume of the given sink to a specified value from 0 to 1 (or more than 1 - if volume should be boosted).
func (c *Client) SetSinkVolume(sinkName string, volume float32) error {
return c.setSinkVolume(sinkName, cvolume{uint32(volume * 0xffff)})
}
Expand All @@ -40,7 +41,7 @@ func (c *Client) setSinkVolume(sinkName string, cvolume cvolume) error {
return err
}

// ToggleMute reverse mute status
// ToggleMute reverses the mute status of the default sink.
func (c *Client) ToggleMute() (bool, error) {
s, err := c.ServerInfo()
if err != nil || s == nil {
Expand All @@ -56,21 +57,27 @@ func (c *Client) ToggleMute() (bool, error) {
return !muted, err
}

// ToggleMute reverse mute status
// SetMute sets mute status of the default sink.
func (c *Client) SetMute(b bool) error {
s, err := c.ServerInfo()
if err != nil || s == nil {
return err
}

return c.SetSinkMute(s.DefaultSink, b)
}

// SetSinkMute sets mute status of the given sink.
func (c *Client) SetSinkMute(sinkName string, b bool) error {
muteCmd := '0'
if b {
muteCmd = '1'
}
_, err = c.request(commandSetSinkMute, uint32Tag, uint32(0xffffffff), stringTag, []byte(s.DefaultSink), byte(0), uint8(muteCmd))
_, err := c.request(commandSetSinkMute, uint32Tag, uint32(0xffffffff), stringTag, []byte(sinkName), byte(0), uint8(muteCmd))
return err
}

// Mute returns whether the default sink is muted.
func (c *Client) Mute() (bool, error) {
s, err := c.ServerInfo()
if err != nil || s == nil {
Expand Down