Results 1 to 6 of 6
  1. #1
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default javax.sound.sampled

    I'm trying to play a .wav file called "TITLE.WAV"
    The following code runs without any errors, but nothing plays...

    Java Code:
    import java.io.File;
    import java.io.IOException;
    import javax.sound.sampled.UnsupportedAudioFileException;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.Clip;
    
    
    class PlayMusic {
    	public static void main(String[] args) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
    		AudioInputStream stream = AudioSystem.getAudioInputStream( new File("D:\\TITLE.WAV"));
    		Clip play = AudioSystem.getClip();
    		play.open(stream);
    		play.loop(1);
    	}
    }

  2. #2
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    Any help for me?

  3. #3
    pmgallardo is offline Member
    Join Date
    Feb 2009
    Posts
    6
    Rep Power
    0

    Default

    It's much complex than that. Take a look at the introduction at the Java Sound API:

    Search in Google for "Java Sound API tutorial"

    Otherwise, if you want to go straight to the point, check the corresponding example in jsresources.org:

    Search in Google for "jsresources Playing an audio file multiple times"

    Sorry for not posting the direct links, but I'm not allowed to do so. ;)

  4. #4
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    Thanks, yes I did end up having a look at that. However, I found another couple of open-source libs that let you play MP3 and OGG files. Have a look here: JavaZOOM

    It also takes care of all the lower-level stuff, meaning I can just point it at a file and it plays. :)

    P.S. You are allowed to post links...

    Thanks anyway for the tips.

  5. #5
    pmgallardo is offline Member
    Join Date
    Feb 2009
    Posts
    6
    Rep Power
    0

    Default

    You're welcome! I saw that your message was quite old, but I wanted to reply anyway, just in case someone gets here.

    Unfortunately, you can only post links after posting seven messages, that's why I can't. I suppose it's a method to avoid advertisement messages...

  6. #6
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

Similar Threads

  1. javax.microedition.io/ javax.bluetooth
    By ahtiven in forum New To Java
    Replies: 3
    Last Post: 01-13-2009, 02:54 PM
  2. Re-playing sound
    By JSK in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-06-2008, 11:34 AM
  3. applet sound
    By marco in forum Java Applets
    Replies: 1
    Last Post: 09-28-2007, 10:31 PM
  4. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 PM
  5. Applets having sound
    By peiceonly in forum Java Applets
    Replies: 2
    Last Post: 03-31-2007, 09:55 AM

Posting Permissions

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