java - Can't hear any sounds from MIDI -


i'm starting java, , tryin' play sounds using midi. i'm following "head first" book. problem can't hear sound, here's code

package pakedz; import javax.sound.midi.*;  public class odtwarzaczmuzyki {   public void graj(){    try {     sequencer sekwenser = midisystem.getsequencer();     system.out.println("mamy sekwenser");     sekwenser.open();      sequence sekwencja = new sequence(sequence.ppq,4);     track sciezka = sekwencja.createtrack();      shortmessage = new shortmessage();     a.setmessage(144, 1, 20, 100);     midievent nutap = new midievent(a, 1);     sciezka.add(nutap);     shortmessage b = new shortmessage();     b.setmessage(128, 1, 44, 100);     midievent nutak = new midievent(b, 16);     sciezka.add(nutak);       sekwenser.setsequence(sekwencja);   } catch (exception ex) {      system.out.println("kutasmarian"); }   };   public static void main (string[] args){  odtwarzaczmuzyki radio = new odtwarzaczmuzyki();  radio.graj();   }  }  

i'm using java 8.0

need call start() method in sequencer. below modified (untested) code.

recommend checking javadoc , official tutorials.

package pakedz; import javax.sound.midi.*;  public class odtwarzaczmuzyki {   public void graj(){     try {       sequencer sekwenser = midisystem.getsequencer();       system.out.println("mamy sekwenser");       sekwenser.open();        sequence sekwencja = new sequence(sequence.ppq,4);       track sciezka = sekwencja.createtrack();        shortmessage = new shortmessage();       a.setmessage(144, 1, 20, 100);       midievent nutap = new midievent(a, 1);       sciezka.add(nutap);       shortmessage b = new shortmessage();       b.setmessage(128, 1, 44, 100);       midievent nutak = new midievent(b, 16);       sciezka.add(nutak);        sekwenser.setsequence(sekwencja);       sekwenser.start();      }     catch (exception ex) {        system.out.println("kutasmarian");     }   };    public static void main (string[] args) {     odtwarzaczmuzyki radio = new odtwarzaczmuzyki();     radio.graj();   } }  

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -