Package com. Sunray. Express. Core. util;
Import java. Io. bufferedinputstream;
Import java. Io. file;
Import java. Io. fileinputstream;
Import java. Io. ioexception;
Import sun. Audio. audioplayer;
Import sun. Audio. audiostream;
Public class playaudio1 {
Static bufferedinputstream Buf;
Public static void start () // This is to read the sound file through the stream
{
Try {
File dir = new file ("E: \ music \ YH \ WAV"); // the path of the file to be played
File [] FS = dir. listfiles ();
For (File file: FS ){
System. Out. println (file. getname ());
File fobject = new file (Dir, file. getname (); // song name, remember that the format is limited
Fileinputstream files = new fileinputstream (fobject );
Buf = new bufferedinputstream (files );
Audiostream audio = new audiostream (BUF );
Audioplayer. Player. Start (audio );
Try {
Thread. Sleep (3000 );
} Catch (interruptedexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
} Catch (ioexception e ){
System. Out. println (E. getmessage ());
}
}
Public void close () throws exception {
Buf. Close ();
}
Public static void loop (){
// Audioplayer. Player.
}
Public static void main (string [] ARGs ){
Start ();
Loop ();
}
}