package mpd import ( "log" "time" "github.com/fhs/gompd/v2/mpd" ) type Player struct { Watcher *mpd.Watcher Client *mpd.Client } func NewPlayer(net string, addr string) (*Player, error) { var ( p Player err error ) p.Watcher, err = mpd.NewWatcher(net, addr, "", "player") if err != nil { log.Fatalf("failed to create a watcher: %v", err) } p.Client, err = mpd.Dial(net, addr) if err != nil { log.Fatalf("failed to start mpd client: %v", err) } go func() { for range time.Tick(30 * time.Second) { p.Client.Ping() } }() return &p, nil } func (p *Player) Close() error { if err := p.Watcher.Close(); err != nil { return err } if err := p.Client.Close(); err != nil { return err } return nil }