Java sequencer playlist
•
Java
I currently have a very simple course:
public class Music { private Sequence sequence; private Sequencer sequencer; public Music(String music) { try { this.sequence = MidiSystem.getSequence(ResourceManager.getMusic(music + ".mid")); this.sequencer = MidiSystem.getSequencer(); this.sequencer.open(); this.sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY); this.sequencer.setSequence(sequence); } catch (Exception e) { System.out.println("Oops - something went wrong."); } } public void play() { this.sequencer.start(); } public void stop() { this.sequencer.stop(); } }
All I have to do is create an object of this class and use the play () – method to start the music But I don't want to play just one MIDI file: once the song is over, I want to start the next one
So I want to create a playlist, such as:
sequence.add("midifile1.mid"); sequence.add("midifile2.mid");
However, I didn't find such an option in the API documentation (there is a createtrack () - option, but I really don't understand how to use it to add more music) I can create multiple objects from this class, but I still don't know when one file ends and the next file should start
Take a look at the online example, which is only confusing What is the best way?
thank you
Solution
I've tried to solve it using metaeventlistener to detect when the sequence is complete:
this.sequencer.addMetaEventListener(new MetaEventListener() { public void Meta(MetaMessage event) { if (event.getType() == 47) { // start new sequence } } });;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码