Solved

MidiUnavailableException question

Posted on 2004-03-24
4
280 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
ID: 10674106
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
ID: 10679864
How do I troubleshoot this problem?
0
 
LVL 92

Accepted Solution

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

Expert Comment

by:objects
ID: 10690651
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 122
java 8 lambda expresssions exception handling 3 75
Java Server Faces parameter pass? 6 39
eclipse argument 14 53
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

895 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

15 Experts available now in Live!

Get 1:1 Help Now