Skip to content

Commit

Permalink
Turns out that controls work in bluetooth as well
Browse files Browse the repository at this point in the history
  • Loading branch information
hilli committed Feb 25, 2024
1 parent 0e27b14 commit 84fd21f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
9 changes: 4 additions & 5 deletions cmd/kefw2/cmd/next_track.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"github.com/hilli/go-kef-w2/kefw2"
"github.com/spf13/cobra"
)

Expand All @@ -15,13 +14,13 @@ var nextTrackCmd = &cobra.Command{
Long: `Play next track when on WiFi source`,
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
currentSource, err := currentSpeaker.Source()
canControlPlayback, err := currentSpeaker.CanControlPlayback()

Check failure on line 17 in cmd/kefw2/cmd/next_track.go

View workflow job for this annotation

GitHub Actions / Release

currentSpeaker.CanControlPlayback undefined (type *kefw2.KEFSpeaker has no field or method CanControlPlayback)
if err != nil {
fmt.Println(err)
fmt.Printf("Can't query source: %s\n", err.Error())
os.Exit(1)
}
if currentSource != kefw2.SourceWiFi {
fmt.Println("Not on WiFi source, not resuming playback")
if !canControlPlayback {
fmt.Println("Not on WiFi/BT source.")
os.Exit(0)
}
err = currentSpeaker.NextTrack()
Expand Down
9 changes: 4 additions & 5 deletions cmd/kefw2/cmd/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"github.com/hilli/go-kef-w2/kefw2"
"github.com/spf13/cobra"
)

Expand All @@ -15,13 +14,13 @@ var pauseCmd = &cobra.Command{
Long: `Pause playback when on WiFi source`,
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
currentSource, err := currentSpeaker.Source()
canControlPlayback, err := currentSpeaker.CanControlPlayback()

Check failure on line 17 in cmd/kefw2/cmd/pause.go

View workflow job for this annotation

GitHub Actions / Release

currentSpeaker.CanControlPlayback undefined (type *kefw2.KEFSpeaker has no field or method CanControlPlayback)
if err != nil {
fmt.Println(err)
fmt.Printf("Can't query source: %s\n", err.Error())
os.Exit(1)
}
if currentSource != kefw2.SourceWiFi {
fmt.Println("Not on WiFi source, not resuming playback")
if !canControlPlayback {
fmt.Println("Not on WiFi/BT source.")
os.Exit(0)
}
if isPlaying, err := currentSpeaker.IsPlaying(); err != nil {
Expand Down
13 changes: 6 additions & 7 deletions cmd/kefw2/cmd/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"fmt"
"os"

"github.com/hilli/go-kef-w2/kefw2"
"github.com/spf13/cobra"
)

// muteCmd toggles the mute state of the speakers
var playCmd = &cobra.Command{
Use: "play",
Short: "Resume playback when on WiFi source if paused",
Long: `Resume playback when on WiFi source if paused`,
Short: "Resume playback when on WiFi/BT source if paused",
Long: `Resume playback when on WiFi/BT source if paused`,
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
currentSource, err := currentSpeaker.Source()
canControlPlayback, err := currentSpeaker.CanControlPlayback()

Check failure on line 17 in cmd/kefw2/cmd/play.go

View workflow job for this annotation

GitHub Actions / Release

currentSpeaker.CanControlPlayback undefined (type *kefw2.KEFSpeaker has no field or method CanControlPlayback)
if err != nil {
fmt.Println(err)
fmt.Printf("Can't query source: %s\n", err.Error())
os.Exit(1)
}
if currentSource != kefw2.SourceWiFi {
fmt.Println("Not on WiFi source, not resuming playback")
if !canControlPlayback {
fmt.Println("Not on WiFi/BT source.")
os.Exit(0)
}
err = currentSpeaker.PlayPause()
Expand Down
9 changes: 4 additions & 5 deletions cmd/kefw2/cmd/prevous_track.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"github.com/hilli/go-kef-w2/kefw2"
"github.com/spf13/cobra"
)

Expand All @@ -16,13 +15,13 @@ var previousTrackCmd = &cobra.Command{
Long: `Play previous track when on WiFi source`,
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
currentSource, err := currentSpeaker.Source()
canControlPlayback, err := currentSpeaker.CanControlPlayback()

Check failure on line 18 in cmd/kefw2/cmd/prevous_track.go

View workflow job for this annotation

GitHub Actions / Release

currentSpeaker.CanControlPlayback undefined (type *kefw2.KEFSpeaker has no field or method CanControlPlayback)
if err != nil {
fmt.Println(err)
fmt.Printf("Can't query source: %s\n", err.Error())
os.Exit(1)
}
if currentSource != kefw2.SourceWiFi {
fmt.Println("Not on WiFi source, not resuming playback")
if !canControlPlayback {
fmt.Println("Not on WiFi/BT source.")
os.Exit(0)
}
err = currentSpeaker.PreviousTrack()
Expand Down
15 changes: 11 additions & 4 deletions cmd/kefw2/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"os"

"github.com/hilli/go-kef-w2/kefw2"
"github.com/qeesung/image2ascii/convert"
"github.com/spf13/cobra"
)
Expand All @@ -26,8 +25,12 @@ var statusCmd = &cobra.Command{
fmt.Println(err)
os.Exit(1)
}

if source == kefw2.SourceWiFi {
canControlPlayback, err := currentSpeaker.CanControlPlayback()

Check failure on line 28 in cmd/kefw2/cmd/status.go

View workflow job for this annotation

GitHub Actions / Release

currentSpeaker.CanControlPlayback undefined (type *kefw2.KEFSpeaker has no field or method CanControlPlayback)
if err != nil {
fmt.Printf("Can't query source: %s\n", err.Error())
os.Exit(1)
}
if canControlPlayback {
pd, err := currentSpeaker.PlayerData()
if err != nil {
fmt.Println(err)
Expand All @@ -44,7 +47,11 @@ var statusCmd = &cobra.Command{
fmt.Println("Artist:", pd.TrackRoles.MediaData.MetaData.Artist)
fmt.Println("Album:", pd.TrackRoles.MediaData.MetaData.Album)
fmt.Println("Track:", pd.TrackRoles.Title)
fmt.Printf("Duration: %s/%s\n", playTime, pd.Status)
if pd.Status.Duration == 0 {
fmt.Printf("Duration: %s\n", playTime)
} else {
fmt.Printf("Duration: %s/%s\n", playTime, pd.Status)
}
// Not so minimalistic output
if minimal, _ := cmd.Flags().GetBool("minimal"); !minimal {
fmt.Print(imageArt2ASCII(pd.TrackRoles.Icon))
Expand Down

0 comments on commit 84fd21f

Please sign in to comment.