Java how to stop audio

Ads
 

Java how to stop audio

hello

i have this code in the main:

try {
            AudioInputStream audio = AudioSystem.getAudioInputStream(new File("x.wav"));
            Clip clip = AudioSystem.getClip();
            clip.open(audio);
            clip.start();
                   }

        catch(UnsupportedAudioFileException uae) {
            System.out.println(uae);
        }
        catch(IOException ioe) {
            System.out.println(ioe);
        }
        catch(LineUnavailableException lua) {
            System.out.println(lua);
        }

I want that when i press the stop button in the gui, the audio stops... please tell me what should i write in the action listener for the button

when i write clip.close(); it shows error

please help

View Answers

June 15, 2011 at 4:59 PM

Use the following code:

JButton button=new JButton("Stop");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
clip.stop();
}
});

For the above,you need to import java.awt.event.* package


June 17, 2011 at 8:04 PM

that is fine

but when i add the clip.stop(); it shows an eexception it thread error... in Netbeans.. it says" cannot find variable clip, create class clip , create field clip.... what should i do?

Ads









Related Tutorials/Questions & Answers:
Java how to stop audio
Java how to stop audio  hello i have this code in the main: try { AudioInputStream audio = AudioSystem.getAudioInputStream(new File...); } I want that when i press the stop button in the gui, the audio stops
how to stop audio (mp3)
how to stop audio (mp3)   if(e.getActionCommand(). equals("Stop")){ player.stop(); } i am making an audio player in which i... stopping it. how should i stop the song keeping in mind i have to play another song
Advertisements
how to play audio track in java applat
how to play audio track in java applat  Sir,i took help of coding in how to play audio track in java applet....nd i found perfect code ..but when i... file...as u see there is no main claas in this coding then how would i run dis
How to stop java scripting engine when the script being run is taking too much time?
How to stop java scripting engine when the script being run is taking too much time?   How to stop java scripting engine when the script being run is taking too much time? for e,g, in case of infinite loop the memory is getting
Play Audio in Java Applet
the sound file. This program will show you how to play a audio clip in your java applet... Play Audio in Java Applet      ... is used to play the sound while stop() method is used for stop the running audio
how to solve 'Stop Running This Script' Error ?
how to solve 'Stop Running This Script' Error ?  Hi.. When opened the page on IE browser(version : 8.0),it gives an java script error (i.e.Stop Running This Script). I have used jsp/servlet for this. Please help to resolved
Java Thread : stop() method
Java Thread : stop() method In this section we are going to describe stop() method with example in java thread. stop() method : Java thread provides method stop to stop any running thread. It is deprecated  as it causes
how to add audio clip in swings with event handling
how to add audio clip in swings with event handling  hello dear, i wanna to play audio clip in java program in JFrame in swings by event handling ,it should be like when i click on a button , audio clip should play , plz tell me
How to stop window closing in "internalFrameClosing" event.
How to stop window closing in "internalFrameClosing" event.  In an internal frame listener in the internalFrameClosing event I want to ask the user to confirm closure with a JDialog. The default close operation for the Internal
How to Remove audio from video file with FFmpeg?
How to Remove audio from video file with FFmpeg?  I have a video... in video. How to remove audio from video file with FFmpeg? thanks   Hi, You can use the '-an' option to remove the audio from video. Check
Need simple java code to start and stop the remote windows service.
Need simple java code to start and stop the remote windows service.  Hi, I Need simple java code to start and stop the remote windows service. Example:There are two servers 1) Server A and 2) Server B. If a notepad.exe file
how to run audio files in net beans using j2me
how to run audio files in net beans using j2me  i am running the audioMidlet in net beans. Now where should i place the .wav files inorder to play them
stop repetition
stop repetition  i want to know use of Hashmap, and its contains key... record more than one time. so could u please guide me how to handle this problem... they have same id so i want to stop repetition
Audio Processing
Audio Processing  Sir, I want implement an audio recognition system by using java.. Is it possible? and tell me the process... thank you
ModuleNotFoundError: No module named 'stop'
ModuleNotFoundError: No module named 'stop'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'stop' How to remove the ModuleNotFoundError: No module named 'stop' error
stop the running hidden server
will need to stop the other process or change the port number(s). how to stop tis...stop the running hidden server  Port 8080 required by Tomcat v6.0 Server at localhost is already in use. The server may already be running in another
playing an audio file
how to solve this problem and also tell me where i should pass my audio clip path   Please visit the following link: http://www.roseindia.net/java...playing an audio file  In playing an audio file we have to take one
ModuleNotFoundError: No module named 'stop-words'
'stop-words' How to remove the ModuleNotFoundError: No module named 'stop...ModuleNotFoundError: No module named 'stop-words'  Hi, My Python... have to install padas library. You can install stop-words python
converter code for audio file
converter code for audio file  how can i convert a audio file to a another file format like mp3
ffmpeg audio from video
ffmpeg audio from video  Hi, How to extract audio from a video file? Thanks
Audio Level Meter
Audio Level Meter  Hello I'm new to programming and I'm trying to make a java application that will "hear" (not record necessarily) the sound and display how loud is.I'm thinking of converting the sound recordings to numbers,so
stop word removal from text file
stop word removal from text file  i need java source code for stop word removal from a text file
ModuleNotFoundError: No module named 'audio'
ModuleNotFoundError: No module named 'audio'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'audio' How to remove the ModuleNotFoundError: No module named 'audio'
HTML5 audio reference
HTML5 audio reference  Hi, Tell me the best url to learn HTML5 audio tags with examples. Thanks   Hi, Learn how to use HTML5 audio tags to play the audio on web page. The HTML5 audio tag is used to play the video
Version of jetty>stop dependency
List of Version of jetty>stop dependency
how to run java application with out stoping
how to run java application with out stoping  I have one java application to download some pdf file but its going to stop downloading after some time it not giving any errors any thing can any one help me to solve this problem
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
ModuleNotFoundError: No module named 'biased-stop-words'
named 'biased-stop-words' How to remove the ModuleNotFoundError: No module named 'biased-stop-words' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'biased-stop-words'  Hi, My
ModuleNotFoundError: No module named 'celery-graceful-stop'
: No module named 'celery-graceful-stop' How to remove the ModuleNotFoundError: No module named 'celery-graceful-stop' error? Thanks   Hi...ModuleNotFoundError: No module named 'celery-graceful-stop'  Hi
ModuleNotFoundError: No module named 'many-stop-words'
named 'many-stop-words' How to remove the ModuleNotFoundError: No module named 'many-stop-words' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'many-stop-words'  Hi, My
ModuleNotFoundError: No module named 'patois-stop-words'
named 'patois-stop-words' How to remove the ModuleNotFoundError: No module named 'patois-stop-words' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'patois-stop-words'  Hi, My

Ads