Results 1 to 2 of 2
  1. #1
    ksemeks is offline Member
    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0

    Default MidiSystem.getSequencer() exception

    Hi, so this is what is up.
    I've keep having an exception thrown, on and on.
    When i try to make a new Sequencer object, i keep getting the javax.sound.midi.MidiUnavailableException: Audio Device Unavailable exception.
    So, here's the code:

    Java Code:
    import javax.sound.midi.*;
    
    public class MiniMusicPlayer1
    {
    	public static void main(String[] args)
    	{
    		try
    		{
    			Sequencer sequencer = MidiSystem.getSequencer();
    			sequencer.open();
    			
    			Sequence seq = new Sequence(Sequence.PPQ, 4);
    			Track track = seq.createTrack();
    			
    			for (int i = 5; i < 61; i += 4)
    			{
    				track.add(makeEvent(144, 1, i, 100, i));
    				track.add(makeEvent(128, 1, i, 100, (i+2)));
    			}
    			
    			sequencer.setSequence(seq);
    			sequencer.setTempoInBPM(220);
    			sequencer.start();			
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    	}
    	
    	public static MidiEvent makeEvent(int comd, int chan, int one, int two, int tick)
    	{
    		MidiEvent event = null;
    		{
    			try
    			{
    				ShortMessage a = new ShortMessage();
    				a.setMessage(comd, chan, one, two);
    				event = new MidiEvent(a, tick);
    			}
    			catch (Exception e)
    			{
    				e.printStackTrace();
    			}
    		}
    		
    		return event;
    	}
    }
    And here's the complete error (at compile):
    Java Code:
    javax.sound.midi.MidiUnavailableException: Audio Device Unavailable
    	at com.sun.media.sound.MixerSynth.implOpen(MixerSynth.java:165)
    	at com.sun.media.sound.AbstractMidiDevice.doOpen(AbstractMidiDevice.java:144)
    	at com.sun.media.sound.AbstractMidiDevice.openInternal(AbstractMidiDevice.java:134)
    	at com.sun.media.sound.AbstractMidiDevice.getReceiverReferenceCounting(AbstractMidiDevice.java:339)
    	at javax.sound.midi.MidiSystem.getReceiver(MidiSystem.java:243)
    	at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:442)
    	at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:348)
    	at MiniMusicPlayer1.main(MiniMusicPlayer1.java:9)
    First i was unable to play MIDI files on my pc, but then i got it to work, so now i can play MIDI files, that's okay.
    I tried even to close every process which uses my sound card, but the error is still there.
    Anyone can help me?

  2. #2
    ksemeks is offline Member
    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 10-25-2010, 07:42 PM
  2. Exception
    By sreejit in forum Advanced Java
    Replies: 2
    Last Post: 10-21-2009, 08:26 AM
  3. exception
    By mohneesh in forum New To Java
    Replies: 3
    Last Post: 08-16-2009, 02:28 PM
  4. exception
    By thamizhisai in forum Advanced Java
    Replies: 9
    Last Post: 05-30-2008, 08:47 AM
  5. Replies: 1
    Last Post: 03-08-2008, 06:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •