Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MidiUnavailableException question

Posted on 2004-03-24
4
Medium Priority
?
312 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

927 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