[Java] find old songs and play the starting part of each midi in the m3u list

Source: Internet
Author: User
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 );
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.