Skip to main content
Participant
December 21, 2008
Question

Prevent Multiple Audio Stream?

  • December 21, 2008
  • 1 reply
  • 454 views
Hello,
I used source code I found for a sound stream visualization (By Peter Dehaan). I added a play and stop button, but when a user clicks on play more then once it loads the stream multiple times. I don't quite know what I should do to prevent this. Hopefully someone can help a noob? thanks.
This topic has been closed for replies.

1 reply

Inspiring
December 21, 2008
Post the code for play button.
myc443lAuthor
Participant
December 21, 2008
the code is right under the music() function call. it's the start_button ...
here is the code just for that though.
Inspiring
December 21, 2008
I took a better look at the code.

First of all, frankly, I don't like this approach very much because it uses nested and anonymous functions. I strongly believe that, with a few exceptions, it is a very bad practice for many practical reasons.

I rearranged code to eliminate this.

Note that this code doesn't reload the sound but replays it if it is at the end or restarts from the position it was paused at.

Also, I added some functionality for graphical representation so that it doesn't create a new sprite if the sound was previously loaded.

This code is not necessarily perfect - you probably will need to polish some things.