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("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?









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 allow or stop using internet - Java Server Faces Questions
how to allow or stop using internet  hello this is my first qusetion I am developing a cybercafe management tool in java,the problem is how to allow or stop the users of cafe using internet by the administrator on other
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 the execution of midlet in j2me?
How to stop the execution of midlet in j2me?  Hi, How to stop the execution of midlet of j2me for a specific amount of time? Thanks & Regards, Sivakumar.JADS_TO_REPLACE_1
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
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 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
stop an infinite for loop - Java Beginners
stop an infinite for loop  class InfiniteForLoop{ public static void main(String[] args) { for(;;){ } } } i want this infinite for loop program to be stopped by another program named kill
Play Audio in Java Applet
Play Audio in Java Applet       Introduction Java has the feature of the playing the sound file. This program will show you how to play a audio clip in your java applet
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 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 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
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
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
Maven dependency for com.netease.cloudmusic.iotsdk - music_audio_base version 0.4.2.20231225160642 is released. Learn to use music_audio_base version 0.4.2.20231225160642 in Maven based Java projects
and Gradle. How to use  com.netease.cloudmusic.iotsdk - music_audio_base...; com.netease.cloudmusic.iotsdk - music_audio_base version 0.4.2.20231225160642 in Java projects... - music_audio_base version 0.4.2.20231225160642 java library in your project
Maven dependency for com.netease.cloudmusic.iotsdk - music_audio_base version 0.4.0-rc7 is released. Learn to use music_audio_base version 0.4.0-rc7 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use ... - music_audio_base version 0.4.0-rc7 java library in your project. ADS... 0.4.0-rc7 of music_audio_base released The developers of  
Maven dependency for com.netease.cloudmusic.iotsdk - music_audio_base version 0.4.1.20231201130928 is released. Learn to use music_audio_base version 0.4.1.20231201130928 in Maven based Java projects
and Gradle. How to use  com.netease.cloudmusic.iotsdk - music_audio_base...; com.netease.cloudmusic.iotsdk - music_audio_base version 0.4.1.20231201130928 in Java projects... - music_audio_base version 0.4.1.20231201130928 java library in your project
Maven dependency for com.netease.cloudmusic.iotsdk - music_audio_base version 0.0.0.1-rc12 is released. Learn to use music_audio_base version 0.0.0.1-rc12 in Maven based Java projects
0.0.0.1-rc12 ) in their Java project if it is based on Maven and Gradle. How...; com.netease.cloudmusic.iotsdk - music_audio_base version 0.0.0.1-rc12 java library... 0.0.0.1-rc12 of music_audio_base released The developers of  
Maven dependency for com.netease.cloudmusic.iotsdk - music_audio_base version 0.4.0-rc42 is released. Learn to use music_audio_base version 0.4.0-rc42 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use ...; com.netease.cloudmusic.iotsdk - music_audio_base version 0.4.0-rc42 java library in your project... 0.4.0-rc42 of music_audio_base released The developers of  
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
Maven dependency for be.yildiz-games - module-audio version 1.0.0 is released. Learn to use module-audio version 1.0.0 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.0 in Java projects. Follow the step by step tutorial...-audio version 1.0.0 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.2 is released. Learn to use module-audio version 1.0.2 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.2 in Java projects. Follow the step by step tutorial...-audio version 1.0.2 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.3 is released. Learn to use module-audio version 1.0.3 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.3 in Java projects. Follow the step by step tutorial...-audio version 1.0.3 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.4 is released. Learn to use module-audio version 1.0.4 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.4 in Java projects. Follow the step by step tutorial...-audio version 1.0.4 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.5 is released. Learn to use module-audio version 1.0.5 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.5 in Java projects. Follow the step by step tutorial...-audio version 1.0.5 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.6 is released. Learn to use module-audio version 1.0.6 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.6 in Java projects. Follow the step by step tutorial...-audio version 1.0.6 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.7 is released. Learn to use module-audio version 1.0.7 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.7 in Java projects. Follow the step by step tutorial...-audio version 1.0.7 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.8 is released. Learn to use module-audio version 1.0.8 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.8 in Java projects. Follow the step by step tutorial...-audio version 1.0.8 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.9 is released. Learn to use module-audio version 1.0.9 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.9 in Java projects. Follow the step by step tutorial...-audio version 1.0.9 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.1 is released. Learn to use module-audio version 2.0.1 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.1 in Java projects. Follow the step by step tutorial...-audio version 2.0.1 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.2 is released. Learn to use module-audio version 2.0.2 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.2 in Java projects. Follow the step by step tutorial...-audio version 2.0.2 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.3 is released. Learn to use module-audio version 2.0.3 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.3 in Java projects. Follow the step by step tutorial...-audio version 2.0.3 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.4 is released. Learn to use module-audio version 2.0.4 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.4 in Java projects. Follow the step by step tutorial...-audio version 2.0.4 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.5 is released. Learn to use module-audio version 2.0.5 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.5 in Java projects. Follow the step by step tutorial...-audio version 2.0.5 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.6 is released. Learn to use module-audio version 2.0.6 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.6 in Java projects. Follow the step by step tutorial...-audio version 2.0.6 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.7 is released. Learn to use module-audio version 2.0.7 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.7 in Java projects. Follow the step by step tutorial...-audio version 2.0.7 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 1.0.1 is released. Learn to use module-audio version 1.0.1 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 1.0.1 in Java projects. Follow the step by step tutorial...-audio version 1.0.1 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for be.yildiz-games - module-audio version 2.0.0 is released. Learn to use module-audio version 2.0.0 in Maven based Java projects
) in their Java project if it is based on Maven and Gradle. How to use  be.yildiz-games... - module-audio version 2.0.0 in Java projects. Follow the step by step tutorial...-audio version 2.0.0 java library in your project. ADS_TO_REPLACE_2 Now you can
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
Maven dependency for be.yildiz-games - module-audio-openal version 1.0.1 is released. Learn to use module-audio-openal version 1.0.1 in Maven based Java projects
version 1.0.1 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  be.yildiz-games - module-audio-openal version 1.0.1 in Java...-audio-openal released The developers of   be.yildiz-games - module-audio
Maven dependency for be.yildiz-games - module-audio-openal version 1.0.3 is released. Learn to use module-audio-openal version 1.0.3 in Maven based Java projects
version 1.0.3 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  be.yildiz-games - module-audio-openal version 1.0.3 in Java...-audio-openal released The developers of   be.yildiz-games - module-audio
Maven dependency for be.yildiz-games - module-audio-openal version 1.0.5 is released. Learn to use module-audio-openal version 1.0.5 in Maven based Java projects
version 1.0.5 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  be.yildiz-games - module-audio-openal version 1.0.5 in Java...-audio-openal released The developers of   be.yildiz-games - module-audio
Maven dependency for com.netease.cloudmusic.iotsdk - music_base_audio_lib_core version 0.4.1.231129182253 is released. Learn to use music_base_audio_lib_core version 0.4.1.231129182253 in Maven based Java projects
( com.netease.cloudmusic.iotsdk - music_base_audio_lib_core version 0.4.1.231129182253 ) in their Java..._audio_lib_core version 0.4.1.231129182253 java library in your project. ADS... 0.4.1.231129182253 of music_base_audio_lib_core released The developers of 
Maven dependency for com.netease.cloudmusic.iotsdk - music_base_audio_lib_new version 0.4.1.20231205203425 is released. Learn to use music_base_audio_lib_new version 0.4.1.20231205203425 in Maven based Java projects
( com.netease.cloudmusic.iotsdk - music_base_audio_lib_new version 0.4.1.20231205203425 ) in their Java..._base_audio_lib_new version 0.4.1.20231205203425 java library in your project... 0.4.1.20231205203425 of music_base_audio_lib_new released The developers of 
Maven dependency for com.netease.cloudmusic.iotsdk - music_audio_base_bridge version 0.4.0-rc7 is released. Learn to use music_audio_base_bridge version 0.4.0-rc7 in Maven based Java projects
and Gradle. How to use  com.netease.cloudmusic.iotsdk - music_audio_base_bridge... - music_audio_base_bridge version 0.4.0-rc7 in Java projects. Follow the step... 0.4.0-rc7 of music_audio_base_bridge released The developers of  
Maven dependency for com.netease.cloudmusic.iotsdk - music_base_audio_lib_core version 0.4.2.20231219170039 is released. Learn to use music_base_audio_lib_core version 0.4.2.20231219170039 in Maven based Java projects
( com.netease.cloudmusic.iotsdk - music_base_audio_lib_core version 0.4.2.20231219170039 ) in their Java... - music_base_audio_lib_core version 0.4.2.20231219170039 java library in your... 0.4.2.20231219170039 of music_base_audio_lib_core released The developers of 
Maven dependency for be.yildiz-games - module-audio-openal version 1.0.6 is released. Learn to use module-audio-openal version 1.0.6 in Maven based Java projects
version 1.0.6 ) in their Java project if it is based on Maven and Gradle. How...? Steps to use  be.yildiz-games - module-audio-openal version 1.0.6 in Java...-audio-openal released The developers of   be.yildiz-games - module-audio

Ads