• Post Reply Bookmark Topic Watch Topic
  • New Topic

Playing sounds  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, I've figured out how to play sounds using sun.audio package.

Essentially I have this method to play a random sound...

The sounds (wav files are a couple of seconds long).

so to play 3 random sounds in sequence...

Does not work, since I guess they each run on there own thread, and they are all invoked practically the same instant, causing 3 sounds to be played simulataneously which is not good.

I posed the question in the threads forum yesterday and only had 1 response which said I could do this just using 1 thread.

I have no idea how to do this, I've tried quite a few things such as...
1.
This doesn't work.

2.
Doesn't seem to work because its meant for swing events

3.
This works, but the sounds have different lengths, so if I don't get it right there will too much of a pause between sounds, or they will overlap.

Can anyone help me fix this?
Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, that other suggestion was from me. Let's take threads completely out of the picture for a minute. Can you show us the shortest possible class to play three sounds in a row from main() ?

Maybe take the code from your Thread class and put it in playSound() with no threading. If that works then we can put the very same code into a single new thread to have it run background to your UI.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing seems to work except when I put a Thread.sleep(...) in after each time I play a sound.

So what I've done is stored the length of each clip in milliseconds, and then just got it to pause for this time, and it works fine.

Can't see any other way to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!