本文整理匯總了Golang中github.com/fhs/gompd/mpd.Client類的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Client類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: playlistInfo
func playlistInfo(_ *Cmd, conn *mpd.Client) (r *Result, err error) {
pl, err := conn.PlaylistInfo(-1, -1)
if err == nil {
r = NewResult("Playlist", pl)
}
return
}
示例2: status
func status(cmd *Cmd, conn *mpd.Client) (r *Result, err error) {
state, err := conn.Status()
if err == nil {
r = NewResult("Status", state)
}
return
}
示例3: listPlaylists
func listPlaylists(_ *Cmd, conn *mpd.Client) (r *Result, err error) {
lists, err := conn.ListPlaylists()
if err == nil {
r = NewResult("StoredPlaylists", lists)
}
return
}
示例4: getFiles
func getFiles(_ *Cmd, conn *mpd.Client) (r *Result, err error) {
files, err := conn.GetFiles()
if err == nil {
r = NewResult("Files", files)
}
return
}
示例5: currentSong
func currentSong(_ *Cmd, conn *mpd.Client) (r *Result, err error) {
info, err := conn.CurrentSong()
if err == nil {
r = NewResult("CurrentSong", info)
}
return
}
示例6: playlistContents
func playlistContents(cmd *Cmd, conn *mpd.Client) (r *Result, err error) {
pl, err := conn.PlaylistContents(cmd.Playlist)
if err == nil {
r = NewResult("StoredPlaylist", NewStoredPlaylist(cmd.Playlist, pl))
}
return
}
示例7: updateMoodDatabase
// Walk over all music files and create a .mood file for each in mood-dir.
func updateMoodDatabase(client *mpd.Client, cfg *Config) error {
if cfg.MoodDir == "" {
return fmt.Errorf("No mood bar directory given (-mood-dir)")
}
if err := os.MkdirAll(cfg.MoodDir, 0777); err != nil {
return err
}
paths, err := client.GetFiles()
if err != nil {
return fmt.Errorf("Cannot get all files from mpd: %v", err)
}
// Use up to N threads:
N := 8
wg := &sync.WaitGroup{}
wg.Add(N)
moodChan := make(chan *MoodInfo, N)
for i := 0; i < N; i++ {
go func() {
for pair := range moodChan {
log.Printf("Processing: %s", pair.MusicFile)
cmd := exec.Command("moodbar", pair.MusicFile, "-o", pair.MoodPath)
if err := cmd.Run(); err != nil {
log.Printf("Failed to execute moodbar on `%s`: %v", pair.MusicFile, err)
}
}
wg.Done()
}()
}
for _, path := range paths {
moodName := strings.Replace(path, string(filepath.Separator), "|", -1)
moodPath := filepath.Join(cfg.MoodDir, moodName)
if _, err := os.Stat(moodPath); err == nil {
// Already exists, Skipping.
continue
}
dataPath := filepath.Join(cfg.MusicDir, path)
moodChan <- &MoodInfo{
MusicFile: dataPath,
MoodPath: moodPath,
}
}
close(moodChan)
wg.Wait()
return nil
}
示例8: setPlaylist
func setPlaylist(cmd *Cmd, conn *mpd.Client) (*Result, error) {
list := conn.BeginCommandList()
list.Clear()
for _, uri := range cmd.Uris {
list.Add(uri)
}
list.Play(0)
return nil, list.End()
}
示例9: addMulti
func addMulti(cmd *Cmd, conn *mpd.Client) (*Result, error) {
list := conn.BeginCommandList()
for i, uri := range cmd.Uris {
if cmd.Pos < 0 {
list.Add(uri)
} else {
list.AddId(uri, cmd.Pos+i)
}
}
return nil, list.End()
}
示例10: update
//Updates the library
func (l *library) update() error {
var conn *mpd.Client
fmt.Println("Connecting to MPD")
conn, err := mpd.Dial("tcp", "127.0.0.1:6600")
if err != nil {
fmt.Println("Error: could not connect to MPD for lib update")
return errors.New("Could not connect to MPD!")
}
defer conn.Close()
_, err = conn.Update("")
if err != nil {
fmt.Println("Error: could not update library!")
return err
}
//Let the update happen
time.Sleep(2 * time.Second)
songs, err := conn.ListAllInfo("/")
if err != nil {
fmt.Println("Error: could not retrieve new library!")
return err
}
l.library = songs
return nil
}
示例11: Render
func (m MPDInstance) Render() (item modules.Item) {
mpdItem := MPDItem{Name: m.name, Markup: "pango"}
mpdFormatData := MPDFormatData{}
var client *go_mpd.Client
if c, err := go_mpd.Dial("tcp", m.host_name+":"+strconv.Itoa(m.port)); err != nil {
log.Error(err.Error())
return nil
} else {
client = c
}
defer func(client *go_mpd.Client) {
if err := client.Close(); err != nil {
log.Error("Failed to disconnect: " + err.Error())
}
}(client)
if attrs, err := client.Status(); err == nil {
if state, ok := attrs["state"]; ok {
mpdFormatData.State = state
} else {
log.Error("Failed to read state.")
return nil
}
} else {
log.Error("Failed to obtain status: " + err.Error())
return nil
}
if attrs, err := client.CurrentSong(); err != nil {
log.Error("Failed to obtain current song: " + err.Error())
return nil
} else {
obj := reflect.ValueOf(&mpdFormatData).Elem()
for key, val := range attrs {
if f := obj.FieldByName(key); f.IsValid() {
val = strings.TrimSpace(val)
f.Set(reflect.ValueOf(val))
}
}
}
buffer := bytes.Buffer{}
if err := m.template.Execute(&buffer, mpdFormatData); err != nil {
log.Error("Failed to render mpd template: " + err.Error())
return nil
} else {
mpdItem.Text = buffer.String()
}
item = mpdItem
return
}
示例12: newLibrary
//Create a new queue
func newLibrary() *library {
var conn *mpd.Client
fmt.Println("Connecting to MPD")
conn, err := mpd.Dial("tcp", "127.0.0.1:6600")
if err != nil {
fmt.Println("Error: could not connect to MPD, exiting")
os.Exit(1)
}
defer conn.Close()
songs, err := conn.ListAllInfo("/")
if err != nil {
fmt.Println("Error: could not connect to MPD, exiting")
os.Exit(1)
}
shuffle(songs)
return &library{
library: songs,
}
}
示例13: add
func add(cmd *Cmd, conn *mpd.Client) (*Result, error) {
return nil, conn.Add(cmd.Uri)
}
示例14: setVolume
func setVolume(cmd *Cmd, conn *mpd.Client) (*Result, error) {
return nil, conn.SetVolume(cmd.Volume)
}
示例15: shuffle
func shuffle(cmd *Cmd, conn *mpd.Client) (*Result, error) {
return nil, conn.Shuffle(cmd.Start, cmd.End)
}