Solved

MidiUnavailableException question

Posted on 2004-03-24
4
277 Views
Last Modified: 2012-06-21
Hi:
    The following code complies but at runntime I get the following error:

javax.sound.midi.MidiUnavailableException: Audio Device Unavailable
at com.sun.media.sound.HeadspaceMixer.open(HeadspaceMixer.java:628)
at com.sun.media.sound.AbstractPlayer.open(AbstractPlayer.java:138)
at MiniMusicPlayer1.main(MiniMusicPlayer1.java:11)

Can someone tell me why I get this error and how can I fix it?

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 ex)
      {
         ex.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){}
     
         return event;
         
      }
     
   }                  
     
0
Comment
Question by:LearningJava
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
Cause the Sequencer is not available :)

If it does exist and is configured correctly perhaps another application is already using it.
0
 

Author Comment

by:LearningJava
Comment Utility
How do I troubleshoot this problem?
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
Make sure the device is present, and check that no other application is using it.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now