-   Programming (
-   -   playing a midi file in java (

linuxmandrake 03-18-2006 10: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 01: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:


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 05:36 AM.