Results 1 to 7 of 7
  1. #1
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default play a wav file repeatedly

    How do I repeatedly play a wav file?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    How are you playing it once? Code please.

  3. #3
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default

    Java Code:
      try 
            {
                File soundFile1 = new File("C:\\won.wav");
               
                if (!soundFile1.exists())
                {
                    System.err.println("Wave file(s) not found!");
                    return;
                }
                AudioInputStream audioIn1 = AudioSystem.getAudioInputStream(soundFile1);
    
                // Get a sound clip resource.
               playing = AudioSystem.getClip();
    
                // Open audio clip and load samples from the audio input stream.
                playing.open(audioIn3);
                
               // Play the file
               playing.start();
    
    
            } 
            catch (javax.sound.sampled.LineUnavailableException e)
            {
                e.printStackTrace();
                return;
            }
            catch (Exception e)
            {
                e.printStackTrace();
                return;
            }

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Try using the Clip methods setLoopPoints(0,-1) and loop(LOOP_CONTINUOUSLY) on playing.

  5. #5
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default

    Could you please elaborate?

  6. #6
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default

    As I tried it out, I only need to put the "playing.loop(...)". And that'd solve the problem. Correct?

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    I've never used AudioSystem.getClip() so I can't really elaborate. You will know if it solves the problem by replacing playing.start() with the other two methods I posted before. My reading of the API docs is that both are needed. (I've always used the Applet method getAudioClip() and the AudioClip method loop() - whether in an applet or not.)

Similar Threads

  1. help to play file.wav in java
    By jperson in forum New To Java
    Replies: 2
    Last Post: 03-26-2010, 04:10 AM
  2. Play wave file out of a jar file
    By schliz in forum Advanced Java
    Replies: 2
    Last Post: 12-03-2009, 02:37 PM
  3. Play avi file in JMF
    By ramkumarm in forum AWT / Swing
    Replies: 0
    Last Post: 04-15-2009, 02:49 PM
  4. play vedio file and flash file in swing
    By rajasekharreddym in forum AWT / Swing
    Replies: 1
    Last Post: 07-30-2008, 09:22 PM
  5. how can I play an mp3 file in java?
    By iliana in forum Networking
    Replies: 1
    Last Post: 05-30-2008, 08:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •