LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   playing a midi file in java (http://www.linuxquestions.org/questions/programming-9/playing-a-midi-file-in-java-425997/)

linuxmandrake 03-18-2006 11:26 AM

playing a midi file in java
 
I want to be able to play stop and loop a midi file. However the code i have accepts a url object but I cant find a way to get that to point to the file on my hdd. it's a java program and not an applet

Mega Man X 03-18-2006 02:22 PM

Since you did not post any code and I don't feel like writing a midi player (you need threads, sequencers, etc), I will give you the basic idea. If you are going for a command line player (For example, to start your application like this: midiplayer <song.mid>), then do something like this:

Code:

public class Main {

    public static void main(String[] args) {
        if (args.length != 1) {
            System.out.println("Usage: java midiplayer <filename>");
        } else {
            MidiPlayer midiPlayer = new MidiPlayer(args[0]);
        }
    }
}

MidiPlayer is the code you have. Make two separated classes: One for the player one for the Mainclass. On the Player's constructor, you will pass the song name (a String).

If you post some code I could give you a hand :)


All times are GMT -5. The time now is 12:11 AM.