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 (hub *Hub) TrackInfo() (mp3.Frame, error) { var f mp3.Frame r, err := os.Open(hub.track) if err != nil { log.Println(err) return f, err } d := mp3.NewDecoder(r) d.Decode(&f) return f, nil }
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 } }
// NewMP3Reader returns a new MP3Reader that reads MP3 frames from r. func NewMP3Reader(r io.Reader) *MP3Reader { return &MP3Reader{d: mp3.NewDecoder(r)} }