I am creating a school project of music player and already created the GUI. I have a jlist on my jframe which populate all the musics listed in there using jfilechooser (done). Now if I clicked a song from my jlist and press the play button, the song should be play while jslider is moving like e.g. the windows media player. Now my problem is, I don't know where to start to code for me to be able to play a sound/music (.wav, .au, .aif, .....) extension format.
Could someone, anyone here be able开发者_如何学运维 to give me a snippet, tutorial or sample code or if someone here has been done this kind of project, could you please share me a sample for me to study...
Thanks so much people.... :)
Check out the javax.sound API. If you already have a File you want to play, it would work something like this (remember to import the javax.sound libraries):
// Gets an input stream for the given file
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
// Gets a clip that can be used for playing an audio file or stream
Clip clip = AudioSystem.getClip();
// Opens the AudioInputStream in the clip
clip.open(ais);
You can then use methods in the Clip object like start, stop, and loop to control playback of the audio file.
精彩评论