How to add music in java game? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to add music in java game?

Do anyone of you guys know how to add music whenever game loads and button pressed please tell?

27th Jul 2019, 11:27 AM
Muhammad Talha
Muhammad Talha - avatar
1 Answer
+ 1
In javaFX there are MediaPlayer Or you can smth like this File soundFile = new File("snd.wav"); AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile); Clip clip = AudioSystem.getClip(); clip.open(ais); clip.setFramePosition(0); clip.start(); Thread.sleep(clip.getMicrosecondLength()/1000); clip.stop(); clip.close();
28th Jul 2019, 11:58 PM
Marina Vasilyova
Marina Vasilyova - avatar