faiface / beep

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

Confused about when to call speaker.Play() #143

Open uzudil opened 2 years ago

uzudil commented 2 years ago

First, thank you for the awesome project!

I have multiple, large music files I want to stream from disk, like this:

When a song plays all the way through, I rewind it (via. streamer.Seek(0)).

Given this kind of usage, what I've come up with is to have ctrl := beep.Ctrl{...} where I keep changing ctrl.Streamer to the song I want to play.

However I'm confused about when I need to call speaker.Play(). Do I just call it once, after constructing ctrl? Or every time I change ctrl.Streamer? Or only after I rewind a streamer?

Thanks for any info!

samhocevar commented 2 years ago

The speaker is not much more than a mixer with a locking mechanism. As long as ctrl.Stream()succeeds, speaker will keep playing your controller. No need to call speaker.Play() more than once on that object. Just make sure you call speaker.Lock() / speaker.Unlock() around places where you change ctrl.Streamer.