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)
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)
*moves to Help*
Hello Pika Art by Dr Unne ~~~ godhatesfraggles
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
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:
To access this method, just initialise a variable of type AudioClip, and pass the method the name or path of the string:Code:public AudioClip loadSound(String filename) { URL soundPath = getClass().getResource(filename); return Applet.newAudioClip(soundPath); }
To start or stop the sound from playing:Code:AudioClip sound = loadSound("hello.wav");
Also, note that to use this method, you need to import the java.net.* and java.applet.* packages.Code:sound.play(); sound.stop();