Home  >  Forum  >  Core Java
Post New Query

How to use Sequencer, MidiEvent and ShortMessage to play sound in java

joined on
October 13,2014
Asked on June 14,2015
Any one know how to play a song/music/a tone using program/code in java. Is it possible to create a sound effect in java using java code? How to use Sequencer, MidiEvent and ShortMessage for sound.
joined on
March 05,2015
Replied on June 14,2015

Yes, It is possible to play a sound using java code.
joined on
February 22,2015
Replied on June 14,2015

If you want to play a sound using Java program you MUST import java sound package in your code i.e.
  import javax.sound.midi.*;
joined on
March 15,2013
Replied on June 14,2015

Yes u can. 
See the example to play a sound

import javax.sound.midi.MidiEvent;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.Track;

public class MiniMusicApp {
public static void main(String[] args) {
MiniMusicApp mini = new MiniMusicApp();
public void play() {
Sequencer player = MidiSystem.getSequencer();
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
ShortMessage a = new ShortMessage();
a.setMessage(144, 1, 44, 100);
MidiEvent noteOn = new MidiEvent(a, 1);
ShortMessage b = new ShortMessage();
b.setMessage(128, 1, 44, 100);
MidiEvent noteOff = new MidiEvent(b, 16);
} catch(Exception ex){


Write Answer

Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us