faiface / beep

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

Feature Request: Be able to cancel a Seq #67

Open gtaubman opened 5 years ago

gtaubman commented 5 years ago

Hello!

Beep has been fantastic to use. However I'm having some difficulty with the following situation.

I have a Seq of a StreamSeekCloser followed by a BeepCallback() to tell me when the audio file is done. Sometimes I'd like to stop streaming early, but If I close the StreamSeekCloser then my BeepCallback gets called.

I took a look at the implementation of Seq and it doesn't look like I can alter the items of the sequence after creation, which means I can't purposefully remove the BeepCallback() and then close the stream.

Would you be open to adding the ability to cancel a Seq which would cancel the current stream and then not run any of the other streams?

Thanks!

tslocum commented 4 years ago

In the mean time, you can assign and change an identifier whenever cancelling a Seq:

streamer := beep.Seq(audioFile.Streamer, beep.Callback(func() {
    if playingFileID != thisFileID {
        return
    }

    go nextTrack()
}))

Full example from ditty: audio.go