Recently, I want to find a midi for ringtones. I used to store thousands of midi, which is hard to find at a time.
Mediaplayer does not support the first part of each curve sampling, so you have to do it yourself.
Search all midi files in the resource manager, drag the mediaplayer, and save the playlist as m3u,
Then, use the following program to play the m3u list.
The midi playback api provided by java is used. The midi playback program of the gray witch is referenced.
Import java. io. File;
Import java. io. FileInputStream;
Import java. io. InputStreamReader;
Import java. io. LineNumberReader;
Import javax. sound. midi. MidiSystem;
Import javax. sound. midi. Sequencer;
Public class MidiPlay {
Public MidiPlay (final File m3u, final int line) throws Exception {
Final Sequencer player = MidiSystem. getSequencer ();
Player. open ();
Final LineNumberReader list = new LineNumberReader (
New InputStreamReader (new FileInputStream (m3u), "UTF-8 "));
// List. setLineNumber (line );
For (int I = 0; I <line; I ++)
List. readLine ();
New Thread (){
Public void run (){
Try {
Int current = line;
String file = list. readLine ();
While (file! = Null ){
Try {
File = file. trim ();
If (! (File. startsWith ("#") | file. length () = 0 )){
File f = new File (file );
If (f. exists ()){
Player. stop ();
Thread. sleep (500 );
Player. setSequence (MidiSystem
. GetSequence (f ));
Player. start ();
System. out. println (current + ":"
+ F. getCanonicalPath ());
Thread. sleep (5000 );
}
}
} Catch (Exception ex ){
Ex. printStackTrace ();
}
File = list. readLine ();
Current ++;
}
} Catch (Exception e ){
E. printStackTrace ();
}
Player. close ();
}
}. Start ();
}
Public static void main (String [] args) throws Exception {
New MidiPlay (new File ("e:/all-midi.m3u"), 170 );
}
}