• Post Reply Bookmark Topic Watch Topic
  • New Topic

Playing 1 sound after another

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to play sounds using threads, but they keep ending up playing at the same time, I really want first one to play, then the next.

This is my code...



Can I get thread1 to start then finish, then thread2 to start.
Also, I will have to actually use several sounds played together in sequence,
so perhaps setting priorities on the threads won't work.

Can anyone help?
Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to do them sequentially you only need one thread. Can you just build a collection of sounds and let one thread work through the collection one at a time? A blocking queue would make a nice collection if you want to add new sounds to the list while the thing is running.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't need to add new sounds as it runs, just need to play 5 or 6 of them.
Its actually for chess moves, eg Qxa5+, would require:
"Queen" "takes" "a" "5" "check".

I have no idea how to do this using 1 thread (or more than 1 thread infact)
Please can you give me an idea.

Thanks for any help.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To avoid having things happen at the same time, don't use multiple threads. To avoid using multiple threads, don't put things like "new Thread()" in your code. (I assume there was a start() for each of these threads - don't do that, either.) Not using thread is very easy. I'm having a hard time understanding where you got the idea that threads would be a good idea here.

Using the method call you've shown, I would guess that if you want 5 sounds one after another, you should try

or

As a slightly more complex example, maybe what you really needed was for all the sounds to occur sequentially, but the rest of the program should more forward without having to wait for all the sounds to finish? In that case, you could put all the sounds into a single thread, e.g.

Now the rest of the program can go on and do whatever you want it to do after the start(), without waiting for the sounds to finish.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but that doesn't work.

They all start to play at the same time because the thread that invokes
SoundBank.playRandomSound();

will not wait for the sound to finish playing, so they all pretty much play at the same time.

Can I fix this without using Thread.sleep();
Thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I suppose we would have to know something about this SoundBank.playRandomSound() and other methods of that class. Is this something you wrote yourself, or does it come from somewhere else? Is it documented anywhere? If you wrote it yourself, what class and methods does it use to actually generate the sounds?
[ July 17, 2007: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!