My, didn't that website mangle your code. That is what happens when you have the wrong line end combination. I have tried to sort it out, by copying to an IDE and using find‑and‑replace and ctrl‑I to sort out the indentation. I hope I have got it right.
Why are you using a static method for stop and instance methods for everything else?
Just thinking out loud. I've never done this before, which is probably why the question made me curious enough to take a look.
Playing a list of files requires implementing the MetaEventListener interface so that you are notified of the end-of-track meta event (event.getType() == 47). This is probably the main question you have.
Rather than using a switch structure, you might consider employing a factory pattern, with a static method like public static MidiPlayer getMidiPlayer(File midi). If "midi" is a file, the factory returns an instance of a MidiFilePlayer. If "midi" is a directory, the factory returns an instance of a MidiDirectoryPlayer class that knows how to cycle through a list of files, randomly or in some order, using MidiFilePlayer. Otherwise, your play() method might smell.
Since the Sequencer start() method is asynchronous, you'd want to think about how to handle the end of file event. For example, you might implement or extend MidiFilePlayer to allow for a synchronous play() method, where the play() method itself waits for the end-of-file event before returning. Or you could provide a playAndWait() method. Otherwise, the caller will need to be able to add itself to the sequencer's MetaEventListener list. Or MidiFilePlayer could emit an end-of-file event. Options options options.
posted 5 years ago
Welcome to the Ranch Mark Koontz
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
how do I do my own kindle-like thing - without amazon