Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java how to stop audio
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Karan Dwivedi
Java how to stop audio
2 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners


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


Advertisement
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 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 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 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.J
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 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
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
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
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
java code to display in audio - Java Beginners
java code to display in audio  Is their any java code, When i enterd text in text field , and when i press submit button,the text i entered should come in voice  Hi friend, Code to help in solving the problem
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
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
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
flex didn't know how to drag and drop video and audio in flip book - Framework
flex didn't know how to drag and drop video and audio in flip book  ... target to add the video audio and photo in this book i am able to add the photo in this book but i didn't able to add video and audio so pls help me for my project
ffmpeg audio from video
ffmpeg audio from video  Hi, How to extract audio from a video file? Thanks
converter code for audio file
converter code for audio file  how can i convert a audio file to a another file format like mp3
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
iPhone play, pause and stop playing music
iPhone play, pause and stop playing music This is the small iPhone SDK example that will show you how to play, pause and stop the music on button... that just drag and paste the music or audio file into the resources folder, which
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
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
audio video conferencing
audio video conferencing  how to develop a chat application in peer to peer setup
Broadcasting audio.. - JSP-Servlet
Broadcasting audio..  i am doing a project on Internet radio. I embeded windows media player,but doesnt know how to broadcast...i need to stream the audio. can anyone give a solution for this. Its very urgent
uploading audio file iphone
uploading audio file iphone  uploading audio file iphone
Audio MIDlet Example
Audio MIDlet Example       This example illustrates how to play audio songs in your... a player for an audio song by using of javax.microedition.media API. As you
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
audio file to play automatically
audio file to play automatically  I want to get an audio file to play automatically when someone visits my site
HTML audio tag
HTML audio tag  Hi, I have written a simple html page to play audio file, I m using audio tag as shown below: Your browser does not support the audio tag. when I open the page using Chrome, it works fine(plays audio
Advertisements
 

 

 

DMCA.com