Exemple #1
0
func (h PlaylistHandler) add(playlist player.Playlist, controls player.Controls,
	data PlaylistCommand) (err error) {
	if data.Album == "" {
		log.Printf("Don't play artists (or nulls)\n")
		return errors.New("Playing artists is not implemented")
	}

	log.Printf("Trying to add %s/%s/%s/%s to playlist (%v)\n",
		data.Category, data.Artist, data.Album, data.Track, data.Immediate)

	var album *model.Album = nil
	var track *model.Track = nil
	if data.Track == "" {
		album, err = model.GetAlbum(h.Music, data.Category, data.Artist,
			data.Album)
	} else {
		track, err = model.GetTrack(h.Music, data.Category, data.Artist,
			data.Album, data.Track)
	}
	if err != nil {
		log.Printf("Album not found.")
		return err
	}

	if data.Immediate {
		err = playlist.Clear()
		if err != nil {
			log.Printf("Error clearing playlist")
			return err
		}
	}

	if track != nil {
		err = playlist.AddTrack(track)
	}
	if album != nil {
		err = playlist.AddAlbum(album)
	}
	if err != nil {
		log.Printf("Error adding album or track %s/%s", data.Album, data.Track)
		return err
	}
	if data.Immediate {
		err = controls.Play()
	}
	return err
}
Exemple #2
0
func (h ControlHandler) currentStatus(w http.ResponseWriter,
	controls player.Controls) (err error) {
	/*
		controls, err := player.NewMpdControls()
		if (err != nil) {
			return err
		}
		defer controls.Close()
	*/

	// get the status
	status, err := controls.Status()
	if err != nil {
		return err
	}
	j, _ := json.Marshal(status)
	w.Write(j)
	return err
}
Exemple #3
0
// dispatch control commands (vol, prev, next)
func (h ControlHandler) command(w http.ResponseWriter,
	r *http.Request, controls player.Controls) (err error) {
	var data ControlCommand
	/*
		controls, err := player.NewMpdControls()
		if (err != nil) {
			return err
		}
		defer controls.Close()
	*/
	err = JsonRequestToType(w, r, &data)
	if err != nil {
		return err
	}

	log.Printf("Received control command '%s'\n", data.Command)
	switch data.Command {
	case "prev":
		err = controls.Prev()
	case "next":
		err = controls.Next()
	case "stop":
		err = controls.Stop()
	case "play":
		err = controls.Play()
	case "pause":
		err = controls.Pause()
	case "volumeDelta":
		err = controls.VolumeDelta(data.VolumeDelta)
	default:
		log.Printf("Unknown command: %s\n", data.Command)
		err = errors.New("Unknown command " + data.Command)
	}
	return err
}