faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.07k stars 152 forks source link

Playing an mp3 file at specific time #148

Closed PaulDotSH closed 2 years ago

PaulDotSH commented 2 years ago

If I play an mp3 file at a specific time two times, even with a mutex, the software panics

func() {
        fmt.Println("a")
        SpeakerMutex.Lock()
        fmt.Println("...")
        f, _ := os.Open("./test/tmp.mp3")
        streamer, format, err := mp3.Decode(f)
        if err != nil {
            log.Fatal(err)
        }
        defer streamer.Close()

        speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))

        done := make(chan bool)
        speaker.Play(beep.Seq(streamer, beep.Callback(func() {
            done <- true
        })))
        <-done
        SpeakerMutex.Unlock()
}

there are 2 functions, this and another one exactly like this but which prints a "b", when they trigger at the same time, one plays the sound and the other one panics exactly after the mutex unlocks