Closed KidLinus closed 6 years ago
Hi! Yes, a beep.Streamer
gets drained when played and thus can naturally only be played once. However, there are two good ways to solve this:
beep.StreamSeekCloser
, which means you can seek it = rewind to an arbitrary point. Doing streamer.Seek(0)
rewinds it to the beginning and it can be played again.beep.Buffer
. Buffer allows you to store audio data in memory (the streamer loaded from file streams directly from the file without loading to memory) and then play it as you wish. You create a buffer, you use buffer.Append(streamer)
to add audio data to the buffer, and then you use buffer.Streamer(start, stop)
to create a streamer that plays from start to stop. For example, buffer.Streamer(0, buffer.Len())
plays the entire content of the buffer. The obtained streamer can be then played through the speaker. To play the audio multiple times, you just create a new streamer every time you need it. Look at the docs for more info.I see, thank you! (Close this issue)
I was looking for this, only to find it while creating a new issue for it (Github pointed me to this one when I was typing in my keywords). Please consider adding this to your readme and as an example. I think this is of utmost importance as many people use your library alongside your pixel engine to create games and playing a certain sound effect in this way is the foremost use case for small WAV sound effects usually.
@gonutz You're right. I'll extend the README to a more fledged tutorial covering most features of Beep as soon as I can.
Cool, thank you! :-)
Hi, I cant figure out how to play the same sound effect multiple times, like every 5 seconds. Can you point me in the right direction?