Prevent error if no players found
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
d1168c838a
commit
5dde9b7d8f
2 changed files with 12 additions and 1 deletions
|
@ -39,6 +39,13 @@ type playingAudioInfo struct {
|
|||
func (g *AudioPlayer) getInfo() (*playingAudioInfo, error) {
|
||||
rawMetadataOutput, err := runCommand(playerctlExecutable, "metadata")
|
||||
if err != nil {
|
||||
// If there's no player open, an error will be thrown by this command
|
||||
// with the below stdout
|
||||
if string(rawMetadataOutput) == "No players found" {
|
||||
return &playingAudioInfo{
|
||||
Status: playerStatusUnknown,
|
||||
}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,11 @@ func runCommand(program string, args ...string) ([]byte, error) {
|
|||
cmd := exec.Command(program, args...)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
err = fmt.Errorf(`failed to execute "%v" (%+v)`, strings.Join(append([]string{program}, args...), " "), err)
|
||||
ne := fmt.Errorf(`failed to execute "%v" (%+v)`, strings.Join(append([]string{program}, args...), " "), err)
|
||||
if x, ok := err.(*exec.ExitError); ok {
|
||||
return bytes.TrimSpace(x.Stderr), ne
|
||||
}
|
||||
return nil, ne
|
||||
}
|
||||
return bytes.TrimSpace(out), err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue