How come this sound only plays once?

Here is a program that illustrates what I am doing:
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import javax.sound.sampled.*;
public class soundApp extends JFrame
    JButton button;                
    Clip clip;
    public soundApp()
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300,300);
        File file = new File("tada.wav"); 
        try
            AudioInputStream audiosource = AudioSystem.getAudioInputStream(file);
            DataLine.Info info =
                new DataLine.Info(Clip.class, audiosource.getFormat());
            clip = (Clip)AudioSystem.getLine(info);  
            clip.open(audiosource);
        catch(UnsupportedAudioFileException e){}
        catch(LineUnavailableException e){}
        catch(IOException e){}
        button = new JButton("Play sound");
        button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e){
            if(e.getActionCommand().equals("Play sound"))
                clip.start();   //HERE IS WHERE I START IT....sorry for caps.
        Container contentpane = getContentPane();
        contentpane.add(button);
        setVisible(true);
  public static void main(String[] args)
      soundApp soundapp = new soundApp();
}How come the clip only plays once?

well the answer is simple, because once the clip will stop the sound will stop too. you have not used any loop or anything that shows that the clip should go on forever. you can give some condition like play the clip unless some other button is pressed or some othe action is performed or so on. just use while or any or iterative or conditional statement to get your ay out.

Similar Messages

  • Making sound only play once.

    Hey guys!
    I'm new to the fourms, quick question the site i'm currently helping out with has an audio clip that gets loaded in through xml, I want this to only play once and then halt, but if the user wanted to click on the volume button it could start on up again without a hassle...
    take a look, let me know your thoughts.
    thanks guys.
    here's the link:  www.manitobah.ca

    well, right now it plays but we just want it to play once, then stop instead of continuiously looping if you know what I mean?

  • Sound only plays in Front left speak on Windows 7 with Xfi Extreme Music??

    I have Xfi Extreme Music (SB0640). In installed the lastes drivers for windows 7 (<a rel="nofollow" href="http://forums.creative.com/t5/forums/postpage/board-id/#]Creative Sound Blaster X-Fi series driver 2.8.003 [/url]), When I run a speaker test all 6 speakers work, however when I use media player, media center etc. Only the front left speaker works.
    Do I need to install creative Alchemy?
    Console Launchers does not load on boot
    Any asistance will be appreciated
    Thanks in advance

    NRe: Sound only plays in Front left speak on Windows 7 with Xfi Extreme Music? You will need to have the Creative Console Launcher which will let you have CMSS-3d or Creative Multichannel Surround Sound. You can find the newest version for your card here......
    <a rel="nofollow" href="http://support.creative.com/downloads/download.aspx?nDownloadId=094"]http://support.creative.com/downloads/download.aspx?nDownloadId=094[/url]
    Honestly though, dont bother with just that. Get Daniel K.'s X-FI support pack which is updated with the newest drivers and applications for your card. Plus, he tweaked those with fixes for installation/integration? under operating systems other than XP.
    That can be found here.......
    <a rel="nofollow" href="http://rapidshare.com/files/234436040/XFI_SupportPack_2_0.exe"]http://rapidshare.com/files/234436040/XFI_SupportPack_2_0.exe[/url]
    And the link is still good.

  • QuickTime will only play ONCE

    Running QT (latest version) on a WinXPsp2 machine.
    Every time we run QT content from a website, it will run once but not run again. There is no error, just unresponsiveness. If we close the browser and reacquire the webpage, it works again ... once. Updating did not help.
    Any ideas?

    Unfortunately this will not help you much, but I discovered this problem on my XP Media Center box AND my Vista laptop. It happened around the same time. All of a sudden, QT movies would only play once. I'd close the browser and it would work again, just once. I use Safari and Firefox as well...guess what, they both work fine. So there is a work around...don't use IE. I do get a QT plugin error though, it says the plugin did not initialize. Seeings that it used to work fine and stopped on both machines at the same time, I'm assuming it was some update, but using Safari or Firefox is quicker and easier than troubleshooting IE...
    Ken Walker

  • How come this program compiles?

    class Base
         Base()
              int i = 100;
              System.out.println(i);
    public class Pri extends Base
         static int i = 200;
         public static void main(String[] args)
              System.out.println(i);
              Pri p = new Pri();
    i get very confused here. in the main, the value of "i" will be printed to the standard output even before the class Pri is instantiated! how come this program can compile?
    your help will be very much appreciated.
    eileen2

    This is because your class Pri extends Base. Because you didn't specify any class Pri constructor, java automatilcally created a no-argument constructor of class Pri with a call to the superclass constructor Base(). You can validate this by adding another Base constructor with arguments and then removing the no-argument Base constructor. Pri() will not compile.

  • Sound only plays in one ear. what is the repair cost/ time?

    sound only plays in one ear. what is the repair cost/ time?

    - Apple will exchange yu iPod for a refurbished one for:
    Apple - Support - iPod - Repair pricing
    If you make an appointment at a Genius Bar ina Apple store they should be abe lto do the exchange.
    - Third-party places are less expensive.  Here is one place. Google for more:
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens

  • HT4623 How come my ipod only updates to ios 6.1.6 and not a iso 7 or 8?

    How come my ipod only updates to ios 6.1.6 and not an ios 7 or 8?

    Because iOS 7 requires 512MB of RAM and iOS 8 requires a dual-core processor. Your device doesn't have either of those.
    (118885)

  • The movie i downloaded plays but the sound only plays some words...how do i fix it??

    the movie i downloaded plays but it skips and the sound only works for 2seconds in the beginning...how do i get the sound to work??? please help

    iTunes - Authorization - Apple Support

  • Is there a way to have audio only play once in Adobe Cp 6?

    I have a project that includes a click box.  If the learner click OUTSIDE the click box then a failure caption comes up with audio.  I'd like to have that audio play only once, even if they continue to click outside the click box.  Right now, if they keep clicking outside the click box, the audio will start playing and I will have multiple instances of the audio playing (and soon it sounds like a cocktail party).  How can I correct this?

    Hi there,
    If you want that the audio should play once after clicking that is possible, but after clicking outside it will replay that audio, but only one instance of audio will be there.
    You can Insert two click boxes and One will cover the whole Slide (Incorrect ) and Other will be inside that click box (for correct region). Then You can apply standard actions on these click boxes when clicked, and include an action to stop triggered audio and another action to play the Audio.
    Like below I added two click boxes and two text captions, Text Captions are not visible in output, they will only be visible after clicking the respective click box:
    The advanced action on correct click box and shows the correct Caption and plays the audio for correct:
    The advanced action on incorrect click box and shows the incorrect Caption and plays the audio for incorrect.
    You can also change the attempts on that click box, by default it is infinite:
    Is this what you want? please reply.

  • Audio only plays once on rollover after imported into muse.

    Hey guys I made a little button which pops up when you roll over it and a beep plays, it works in the edge preview but when imported into muse and previewed it only plays the audio once.... the animation repeats but the sound doesn't. The sound is part of the button symbol timeline. and it is set to play.
    My actions are on the main stage, on roll over play 'about_button'
    Thanks for any help with this it's driving me mad....

    Hi thechossy,
    Not sure if this is what you are looking for but passing it on nevertheless How to Create a Loop in Adobe Edge Animate | cyprich.com
    Thanks,
    Preran

  • Audio only plays once

    I am trying to convert some VCD clips to dv files in order to edit them in FCP and burn to a DVD. This is the sequence of conversions etc. that I perform:
    Step 1. Use VCDGearX to convert the (VCD)DAT to mpg. The resultant file plays fine in QuickTime.
    Step 2. Use ffmpegX to convert the mpg file to DV, using all the default settings. Resultant file plays fine with QuickTime.
    Step 3. Import DV file into Final Cut Pro 4. DV file imports OK and audio plays once only. Thereafter I cannot hear the audio, and no audio waveform can be seen, even after rendering.
    If I quit FCP and reopen, the audio will play only once again.
    Can anyone tell me what is happening, how I can get the audio and the waveform to appear as it should.
    iMac G4   Mac OS X (10.4.6)  

    Glad you found what you need...
    New Discussions ResponsesThe new system for discussions asks that after you mark your question as Answered, you take the time to mark any posts that have aided you with the tag and the post that provided your answer with the tag. This not only gives points to the posters, but points anyone searching for answers to similar problems to the proper posts.
    If we use the forums properly they will work well...
    Patrick

  • Sound only plays through one earphone

    hey i'm new here so bear with me if i make any mistakes.
    recently my 30GB ipod video started playing sound only through one earphone, i tried several different pairs but the problem was the same. i took it to my local apple shop and they said it can't be fixed, but you could have it replaced for £109, i'm a student i don't have £109!
    he said i could get a radio remote, something like this:
    http://www.amazon.co.uk/Apple-MA070G-C-Radio-Remote/dp/B000MTEER4/ref=pdbbs_sr4?ie=UTF8&s=electronics&qid=1200145716&sr=8-4
    i wasn't prepared to spend that much so just got a standard remote control with no radio function, however i didn't realise that this had to be connected through the headphone socket! what's the cheapest and most convenient way i can get sound going through both my headphones again? can i get a standard remote that just goes through the adapter at the bottom?
    many thanks, jack
    Message was edited by: kaiser_jack

    I have the same problem! Im looking for anyway just to hear music out of both head phones, but I don't care which port I use. If anyone knows any ways I could soder(sp?) together a par of head phones with a iPod usb-thingy could you tell me how to?

  • How come I can't play videos anymore?

    I'm running iPhoto v 7.1.5; OS X 10.9.1, but I can't play videos anymore? How is this possible?  What do I need to do? Please help.

    iPhoto v7 (or iPhoto 08 dates from 2007, and is looking for Quicktime 7 to play the videos - the version of Quicktime that was current then. 10.9 uses Quicktime X.
    Two options:
    Upgrade to a more recent version of iPhoto
    or
    Install QUicktime 7. You'll find an installer here
    http://support.apple.com/kb/DL923

  • HT4009 I cant buy gem in app its always price with dollar., how come? I only have id apple indonesia.. Pleaseee help me

    I cant buy gem pakopang line gem.. I have account id indonesia. But in the pokopang i must buy with a dlar. How come i only have a id indonesia

    If it's a debit card then I don't think that they are still accepted as a valid payment method - they are not listed on this page and there have been a number of posts recently about them being declined
    If it is a credit card then is it registered to exactly the same name and address (including format and spacing etc) that you have on your iTunes account, it was issued by a Lebanese bank and you are currently in the Lebanon ? If it is then you could check with the card issuer to see if it's them that are declining it, and if not then try contacting iTunes support and see if they know why it's being declined : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • How come my sound bar is not displayed ?

    Can only play music to her speaker when pluged into charge but will also see sound bar on display to adjust volume but when taken off charge can not play sound or see the adjust volume bar , what can I do to fix it

    Those are preferences you speify from INSIDE The Finder:
    Finder > Preferences:

Maybe you are looking for

  • I cannot use my Acrobat XI downloaded with my one year subscription. It tells me my trial has expired and i need to license it. but I have no serial number.

    I cannot use my Acrobat XI downloaded with my one year subscription. It tells me my trial has expired and i need to license it. but I have no serial number.

  • Mail with jpg attachments not sending

    I've tried repeatedly sending jpg photos in Mail, but they are never successfully sent.  The Send icon keeps spinning and spinning and never stops.  I end up having to go into the Outbox and deleting the message, then doing a Force Quit Mail before I

  • Error During Solaris 8 Installation

    Hi I am getting the following error message while installing solaris 8 on my intel based computer. Error : Could not mount filesystems . Error : could not opern /a/etc/vfstab . and the installation halts and the prompt comes up. The packages are part

  • CCIE Security

    Hello, I am preparing for the CCIE Security exam and have a few questions. 1. Is the CCIE Written exam going to be more focussed on the ASDM view of configuring the firewalls much like the CCSP exams? If so then I can work on getting more hands on wi

  • Verity search not indexing

    I have recently upgraded to coldfusion 8. I reworked my verity searches but the main one of the website times out. I have gotten it to complete a couple of times but this time it will not complete. I have no clue what to change to make it index. I wo