func (hub *Hub) streamStep() { r, err := os.Open(hub.track) defer r.Close() if err != nil { log.Println(err) return } d := mp3.NewDecoder(r) var f mp3.Frame for { if err := d.Decode(&f); err != nil { log.Println(err) return } b := make([]byte, f.Size()) f.Reader().Read(b) hub.SendMessage(b) time.Sleep(f.Duration()) } }
func getMp3Length(path string) (totalTime int64) { // Returns length in milliseconds r, err := os.Open(path) if err != nil { //fmt.Println(err) return } d := mp3.NewDecoder(r) var f mp3.Frame totalTime = 0 for { if err := d.Decode(&f); err != nil { //fmt.Println(err) return } totalTime += f.Duration().Nanoseconds() / 1000000 } }