Results 1 to 7 of 7
Thread: javax.sound play midi
- 06-05-2010, 09:42 AM #1
javax.sound play midi
I want to make a javax.sound applet/application.
But now I can only open and play an audio (.au) file.
now I want to open and play a .mid file.
I've read it's possible to do that with a sequence(r), but I don't know how I need to use it.
Does someone have a simple example for open and play a .mid file?
Thanks,
Dennis
- 06-05-2010, 11:47 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yeas that's the way, Sequence will done the job. Open the stream before start it.
Java Code:Sequencer sequencer = MidiSystem.getSequencer(); sequencer.setSequence(MidiSystem.getSequence(midi_file)); sequencer.open(); sequencer.start();
- 06-05-2010, 11:49 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Use it within a separate thread if you can.
- 06-05-2010, 05:19 PM #4
When I do that I get an error. (my IDE is "EclipseSDK")
This is my source-code:
And this is the error that I recieve:Java Code:import java.io.File; import java.io.IOException; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiSystem; import javax.sound.midi.MidiUnavailableException; import javax.sound.midi.Sequencer; public class sound3 extends java.applet.Applet { private static final long serialVersionUID = 1L; public sound3() { Thread soundThread = new Thread(soundRun); soundThread.start(); } Runnable soundRun = new Runnable(){ public void run() { try{ Sequencer sequencer = MidiSystem.getSequencer(); sequencer.setSequence(MidiSystem.getSequence(new File("TLSTN.MID"))); sequencer.open(); sequencer.start(); }catch(InvalidMidiDataException ex){ ex.printStackTrace(); }catch(IOException ex){ ex.printStackTrace(); }catch(MidiUnavailableException ex){ ex.printStackTrace(); } } }; }
Java Code:javax.sound.midi.InvalidMidiDataException: could not get sequence from file at javax.sound.midi.MidiSystem.getSequence(MidiSystem.java:854) at sound3$1.run(sound3.java:23) at java.lang.Thread.run(Thread.java:619)
- 06-05-2010, 05:26 PM #5
I think it's already solved, my .mid file isn't a good MIDI file.
when I tried it with a .mid file from internet it's working.
Thanks! ;)
- 06-08-2010, 04:54 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
File formats can be corrupted easily.
- 06-08-2010, 04:59 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Regarding your question. It's better to validate with a endless loop. It's much easier way to work on. Something like this.
Java Code:while(true) { if(sequencer.isRunning()) { try { Thread.sleep(1000); } catch(Exception ex) { // Relevant process } } }
Similar Threads
-
Create and play midi notes
By tor in forum New To JavaReplies: 0Last Post: 04-26-2010, 12:18 AM -
Trouble using midi sound package
By isum12b in forum EclipseReplies: 1Last Post: 04-05-2009, 10:11 AM -
Make sound play in a java application
By lenny in forum AWT / SwingReplies: 2Last Post: 08-13-2007, 11:45 AM -
how to play MIDI in java application?
By oregon in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 02:26 AM -
Play sound and Video in a Mobile Phone
By luisarca in forum Sun Java Wireless ToolkitReplies: 2Last Post: 05-23-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks