• Post Reply Bookmark Topic Watch Topic
  • New Topic

AudioPlayer issues  RSS feed

 
Louis Kounios
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys! I'm new in Java and I'm trying to write a small game.

What I want to do is play a sound as soon as my program runs, and stop that sound and play a different one as soon as the user clicks on "Start". The problem is that the previous sound will not stop playing, but as soon as I click on "Start" in my GUI, the new sound plays and I can hear both of them playing simultaneously.

I won't post the whole code, because I don't think it's necessary.

Here's my class for sound playback:

...and here's my game (only the important parts):


I really do not understand what is going wrong. In one of my experiments, I tried placing the "AudioPlayer.player.stop(ContinuousAudioDataStream/AudioDataStream);" inside my startSound methods of the PlaySound class, and the sound didn't start at all, because the stop() method was directly following the start() method. This proved to me that the stop() method is working.

Sorry if the code is unclear in any way and thanks in advance for any help coming my way. If you think I neglected to share any required, please let me know.

Louis.

PS: Any suggestions to improve my code readability etc are welcome.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of the com.sun... classes, I'd go with the stuff in javax.sound.sampled - it's in the API, it's much more capable and liable to be more mature.
 
Louis Kounios
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester, I heeded your advice and went with javax.sound.sampled. Thanks for that!

Now that I'm almost close to finalising the basic stuff, I'm trying to finish my OO class for sound playback with the following addition: speed up/slow down the sound during playback. This is what I've done so far:

And what I get when I run my test class (with a GUI) is "Exception in thread "main" java.lang.IllegalArgumentException: Unsupported control type: Sample Rate". If I comment out both the sampleControl = (FloatControl)... and sampleControl.setValue() methods, the program runs fine. The problem is, I already tried reading the API and I do not understand what I'm doing wrong. MASTER_GAIN works like a charm.

Can anyone help me with this?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!