How to play mp3 files in java using eclipse?
danie93
0
Newbie Poster
Recommended Answers
Jump to PostA few minutes on google and here you go...
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; try{ AudioInputStream audioInputStream =AudioSystem.getAudioInputStream(this.getClass().getResource("path of relative sound file in src folder")); Clip clip = AudioSystem.getClip(); clip.open(audioInputStream); clip.start( ); } catch(Exception ex) { }
Next time try to write your own code …
Jump to Post... further to the JavaFX suggestion...
just for fun I tried it. It's really easy, apart from one gotcha that took a little research. Anyway, here's the resultYou create a JavaFX MediaPlayer, passing it the URI of the mp3 file, and call its play() method. The following code gets …
All 6 Replies
milil
24
Newbie Poster
raj.mscking
0
Newbie Poster
JamesCherrill
4,667
Most Valuable Poster
Team Colleague
Featured Poster
stultuske
1,116
Posting Maven
Featured Poster
JamesCherrill
4,667
Most Valuable Poster
Team Colleague
Featured Poster
JamesCherrill
4,667
Most Valuable Poster
Team Colleague
Featured Poster
stultuske
commented:
nice. might take a look myself whenever I write me a new one.
+13
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.