• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Playing sounds

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic