Skip to content

Commit d24701c

Browse files
committed
added mute and unmute commands
Closes: #66
1 parent ba871fd commit d24701c

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Available Commands:
5555
help Help about any command
5656
load Load and play media on the chromecast
5757
ls List devices
58+
mute Mute the chromecast
5859
next Play the next available media
5960
pause Pause the currently playing media on the chromecast
6061
playlist Load and play media on the chromecast
@@ -67,6 +68,7 @@ Available Commands:
6768
stop Stop casting
6869
tts text-to-speech
6970
ui Run the UI
71+
unmute Unmute the chromecast
7072
unpause Unpause the currently playing media on the chromecast
7173
volume Get or set volume
7274
watch Watch all events sent from a chromecast device
@@ -78,6 +80,7 @@ Flags:
7880
-n, --device-name string chromecast device name
7981
--disable-cache disable the cache
8082
--dns-timeout int Multicast DNS timeout in seconds when searching for chromecast DNS entries (default 3)
83+
--first Use first cast device found
8184
-h, --help help for go-chromecast
8285
-i, --iface string Network interface to use when looking for a local address to use for the http server or for use with multicast dns discovery
8386
-p, --port string Port of the chromecast device if 'addr' is specified (default "8009")

cmd/mute.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2020 Jonathan Pentecost <[email protected]>
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/spf13/cobra"
21+
)
22+
23+
// muteCmd represents the mute command
24+
var muteCmd = &cobra.Command{
25+
Use: "mute",
26+
Short: "Mute the chromecast",
27+
Run: func(cmd *cobra.Command, args []string) {
28+
app, err := castApplication(cmd, args)
29+
if err != nil {
30+
fmt.Printf("unable to get cast application: %v\n", err)
31+
return
32+
}
33+
if err := app.SetMuted(true); err != nil {
34+
fmt.Printf("unable to mute cast application: %v\n", err)
35+
return
36+
}
37+
},
38+
}
39+
40+
func init() {
41+
rootCmd.AddCommand(muteCmd)
42+
}

cmd/unmute.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2020 Jonathan Pentecost <[email protected]>
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/spf13/cobra"
21+
)
22+
23+
// unmuteCmd represents the unmute command
24+
var unmuteCmd = &cobra.Command{
25+
Use: "unmute",
26+
Short: "Unmute the chromecast",
27+
Run: func(cmd *cobra.Command, args []string) {
28+
app, err := castApplication(cmd, args)
29+
if err != nil {
30+
fmt.Printf("unable to get cast application: %v\n", err)
31+
return
32+
}
33+
if err := app.SetMuted(false); err != nil {
34+
fmt.Printf("unable to unmute cast application: %v\n", err)
35+
return
36+
}
37+
},
38+
}
39+
40+
func init() {
41+
rootCmd.AddCommand(unmuteCmd)
42+
}

testdata/helptext.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Available Commands:
1616
help Help about any command
1717
load Load and play media on the chromecast
1818
ls List devices
19+
mute Mute the chromecast
1920
next Play the next available media
2021
pause Pause the currently playing media on the chromecast
2122
playlist Load and play media on the chromecast
@@ -28,6 +29,7 @@ Available Commands:
2829
stop Stop casting
2930
tts text-to-speech
3031
ui Run the UI
32+
unmute Unmute the chromecast
3133
unpause Unpause the currently playing media on the chromecast
3234
volume Get or set volume
3335
watch Watch all events sent from a chromecast device

0 commit comments

Comments
 (0)