Exemple #1
0
func playHandler(w http.ResponseWriter, r *http.Request) {
	atomic.AddInt32(&idx, int32(1))
	if err := player.Stop(); err != nil {
		sendErr(w, err)
		return
	}

	if list, err := playlist(); err != nil {
		sendErr(w, err)
		return
	} else {
		list = random(list, maxSize)
		fmt.Printf("ready playlist:\n%#v\n", list)
		go func(list []string, _idx int32) {
			for _, fi := range list {
				player.ReadyToPlay()
				if atomic.LoadInt32(&idx) != _idx {
					fmt.Println("play break with ", _idx)
					player.ResetToPlay()
					break
				}
				fmt.Println("ready to play: ", fi)
				player.Play(fi)
			}
		}(list, atomic.LoadInt32(&idx))
	}
	gotoIndex(w, r)
}
func handlePlayCommand(tokens []string) {
	if len(tokens) != 2 {
		fmt.Println("USAGE: play <name>")
		return
	}

	e := lib.Find(tokens[1])
	if e == nil {
		fmt.Println("The music", tokens[1], "does not exist.")
		return
	}

	// player.Play(e.Source, e.Type, ctrl, signal)
	player.Play(e.Source, e.Type)
}