Results 1 to 3 of 3
  1. #1
    jperson is offline Member
    Join Date
    Jan 2010
    Posts
    61
    Rep Power
    0

    Default help to play file.wav in java

    i make this simple code to play .wave file

    Java Code:
    public class Main {
    
        public static void main(String[] args) throws FileNotFoundException, IOException {
    
            InputStream in = new FileInputStream("music/buzz.wav");
    
            AudioStream as = new AudioStream(in);
    
            AudioPlayer.player.start(as);
    
            AudioPlayer.player.stop(as);
    
        }
    }
    the code run correctly but the file not play , what's the problem ???

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    My guess would be that you're starting the playback of your WAV and the immediately stopping it. Try inserting

    Java Code:
    try {
      Thread.sleep (5000);
    } catch (Throwable t) { }
    between the start() and the stop(). If i'm right, you should hear the sound for 5 seconds.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Play wave file out of a jar file
    By schliz in forum Advanced Java
    Replies: 2
    Last Post: 12-03-2009, 02:37 PM
  2. Play avi file in JMF
    By ramkumarm in forum AWT / Swing
    Replies: 0
    Last Post: 04-15-2009, 02:49 PM
  3. How to play Flash File inmy frame?
    By makpandian in forum AWT / Swing
    Replies: 1
    Last Post: 02-12-2009, 02:01 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

Posting Permissions

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