what's the Java code to play music | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

what's the Java code to play music

I wanted to play a sound when user clicks a button

7th Jul 2016, 8:48 AM
calvin rodrigues
calvin rodrigues - avatar
2 Answers
0
I'm not sure what your specific problem is, but I will give a few steps to play your sound/music. I'm also going to assume that you have moderate Java programming knowledge and I'm going to assume that the "button" has already been made. 1.) Save your audio file as either an AU or WAV file. If you are making a java applet, you have to your audio file saved with an .au extension. 2.) Copy the path of the file from the file explorer. Basically, open the file explorer, find the audio file, and click & copy the path which is on the top. 3.) Make a variable for the audio with the C:// or E:// path. 4.) Then, you make an if/else statement to test if this sound works on button click. If you still need help with these steps, let me know. Otherwise, I hope I made an honest effort to solve your issue.
24th Jul 2016, 12:17 AM
Scylla
Scylla - avatar
0
Jawa
20th Jan 2022, 5:04 AM
Mitalee Bachle
Mitalee Bachle - avatar