Stopping/Pausing all threads before they are created for soundloop
I am trying to create a soundboard program which will play sounds using the Javazoom mp3 package.
I create a new thread for each button as i wish to stop the thread each time the button is clicked in order to stop the currently playing sound and start it again so开发者_运维百科 selecting a new random sound clip. My logic was that this will enable to user to click the button before the current sound has finished playing and it will stop the sound and start the next clip.
My question is there some way to stop a thread before it is created or ensure that a thread stops itself if it is currently running and then restarts. I have tried moving the thread creation object to outside of the actionlistener then attempting to .stop before .start however this does not work.
Thankyou for any help
I suggest converting your sound player sound threads to tasks and use an ExecutorService to run them. An ExecutorService
gives you better control when creating, running and stopping threads.
There are various ExecutorService
implementations, which may be created using the static factory methods from the Executors class.
精彩评论