Results 1 to 4 of 4

Thread: How can I play music files in a java program?

  1. #1

    Default How can I play music files in a java program?

    How can I play music files in a java (NOT JavaScript) program?

    Preferably mp3's as I know how to play mid files (don't come out too well though)

  2. #2
    rowr Recognized Member Leeza's Avatar
    Join Date
    Aug 2001
    Location
    The long hard road out of hell.
    Posts
    17,974
    Contributions
    • Former Administrator
    • Former Cid's Knight

    Default

    *moves to Help*
    Hello Pika Art by Dr Unne ~~~ godhatesfraggles

  3. #3

    Default

    While I am not just going to give you an answer, I can give you a resource to read. Point is, there are a billion different ways to do this, but the best would be to learn and understand the JMF: Java medi frame work.

    It can be a bare if you are not to experienced with Java, but it is a clean useful set to use - even though it is java
    Here is the basic FAQ: http://java.sun.com/products/java-me...1/faq-jmf.html

    This is a dated article, but it I still have it in my Bookmarks it is an interesting article, and an ok read. Not much educationl value, but more of a preception on the purpose of the JMF.
    http://www.javaworld.com/javaworld/j...-06-media.html

    This again, is just one way to aim what you are going for. Like anything else in Java, it is clunky, and a tad slow. The set makes life a ton easier when working with media though
    good luck

    Bipper

  4. #4
    i n v i s i b l e Tech Admin o_O's Avatar
    Join Date
    Jun 2001
    Location
    New Zealand
    Posts
    2,957
    Blog Entries
    1

    FFXIV Character

    Humphrey Squibbles (Sargatanas)

    Default

    MP3 is a bit of a format to avoid when it comes to Java, since it isn't natively supported. If you could sacrifice the MP3s for MIDI or WAV files, a quick and easy method you could include would be something like:
    Code:
    public AudioClip loadSound(String filename) {
       URL soundPath = getClass().getResource(filename);
       return Applet.newAudioClip(soundPath);
    }
    To access this method, just initialise a variable of type AudioClip, and pass the method the name or path of the string:
    Code:
    AudioClip sound = loadSound("hello.wav");
    To start or stop the sound from playing:
    Code:
    sound.play();
    sound.stop();
    Also, note that to use this method, you need to import the java.net.* and java.applet.* packages.

Posting Permissions

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