It's not a secret anymore!*
The moose likes Other JSE/JEE APIs and the fly likes Stopping a looping javax.sound.sampled audio clip Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Stopping a looping javax.sound.sampled audio clip" Watch "Stopping a looping javax.sound.sampled audio clip" New topic
Author

Stopping a looping javax.sound.sampled audio clip

Al Dunne
Greenhorn

Joined: Apr 24, 2011
Posts: 13
Hi all,

I'm fairly new to this so I hope I've posted this to the correct place.

I'm completing a project where a user gets to press a few buttons and they will see a waveform change and hear the amplitude of a sound increase or decrease. To get the sounds to play I'm using javax.sound.sampled.*

My code is as follows (the buttons the user presses are in a seperate GUI built class):-



The actual sounds are 10 seconds long so I want them to loop continuously until the user either increases or decreases the amplitude.

All my code is working fine. However, the problem I'm having is that everytime the user clicks the increase amplitude button and calls the playSound method, a new audio line gets opened and the sounds play at the same time.

Is there a way I can close all existing audio lines before a new one is opened? I've been looking for a couple of hours now but am getting more and more frustrated/confused.

Any help would be much appreciated.

Al.


Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

Welcome to Java Ranch! Your question looks like it will required specific expertise in the javax.sound API, so I'll move it to Other JSE/JEE APIs. I'm sure someone will be along to answer it soon.
Al Dunne
Greenhorn

Joined: Apr 24, 2011
Posts: 13
Ok thanks Greg.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Maybe I'm misunderstanding something, but if you wanted to stop a Clip, why wouldn't you just call its "stop" method?
Al Dunne
Greenhorn

Joined: Apr 24, 2011
Posts: 13
Hi Paul,

I'm fairly new to this so I was getting confused about where I should call the stop method. I had it in a few places but it wasn't working. I really don't understand about Clips etc yet.

I got the solution on another website yesterday afternoon. It was to put the following code before the try-catch in the playSound method.



Thanks for your reply though.

Al.
 
GeeCON Prague 2014
 
subject: Stopping a looping javax.sound.sampled audio clip