Solved

MidiUnavailableException question

Posted on 2004-03-24
4
283 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 38
Maven Project: Hibernate Dependencies Conflict 10 24
hibernate insert example 13 29
servlet example 17 32
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

810 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