示例#1
0
文件: main.go 项目: hoffoo/pickup
func testPlayback(conf *config.Config, music model.Collection) error {
	playlist := player.NewMpdPlaylist(conf)
	playlist.Clear()

	// add any old album
	album := music.Categories[0].Artists[3].Albums[2]
	log.Printf("Playing album %s - %s\n", album.Artist, album.Name)
	playlist.AddAlbum(album)

	// get the contents of the playlist
	currentTracks, err := playlist.List()
	log.Printf("Current playlist: (%d tracks)", len(currentTracks))
	for _, track := range currentTracks {
		log.Printf("%s\n", track)
	}
	return err
}
示例#2
0
文件: playlist.go 项目: hoffoo/pickup
// Return a list of albums or a specific album
func (h PlaylistHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	controls, err := player.NewMpdControls(h.conf)
	defer controls.Close()
	playlist := player.NewMpdPlaylist(h.conf)
	defer playlist.Close()

	switch r.Method {
	case "GET":
		log.Printf("GET: Showing current playlist\n")
		err = h.currentPlaylist(w, playlist)
	case "POST":
		err = h.command(w, r, playlist, controls)
	}

	if err != nil {
		log.Printf("Error detected in /playlist: %s", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}