-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback or Signal for Playback complete #230
Comments
You can get underneath the player with a custom // TriggerReader invokes a callback when EOF is reached.
type TriggerReader struct {
r io.Reader
cb func()
}
func (t *TriggerReader) Read(p []byte) (n int, err error) {
n, err = t.r.Read(p)
if err == io.EOF {
t.Callback()
}
return n, err
}
func (t *TriggerReader) Callback() {
if t.cb != nil {
t.cb()
}
} done := make(chan struct{})
data := []byte{...}
src := bytes.NewReader(data)
src = &TriggerReader{r: src, cb: func() {close(done)}}
p := ctx.NewPlayer(src)
p.Play()
<-done |
I was wondering why you need to detect the timing when the player ends in the first place. |
I have a program that wants to exit once playback is finished, but you could also imagine advancing a track in a playlist, or similar. |
Another use case could be that we want to wait for the player to finish and all the samples be sent to the driver before suspending so that the last couple of samples don't get lost. I was discussing this regarding Beep from this comment down: gopxl/beep#137 (comment) |
Instead of polling the player, perhaps it would be better to offer either a callback or a channel style API.
The text was updated successfully, but these errors were encountered: