Opening instruments with appletviewer vs. browser

M

Momo

A Java program that I've written that makes sounds works fine when I
test it with appletviewer, but not when I use a browser (Firefox or
Explorer). The difference is that when I call the MidiSystem
synthesizer with getAvailableInstruments, I get a bunch of instruments
(411) when running it with appletviewer, but none when using a browser.
Why the difference? A short program that demonstrates my problem is
below.

Momo


import javax.swing.*;
import javax.sound.midi.*;

public class SimpleSound extends JApplet
{
public void init()
{
try {
Synthesizer synth=MidiSystem.getSynthesizer();
synth.open();
Instrument[] instr=synth.getAvailableInstruments();
JOptionPane.showMessageDialog(null,"instr.length="+instr.length);
}
catch (MidiUnavailableException e) {
}
}
}
 
M

Momo

This is just a test program to demonstrate the error. When I run the
program below it doesn't throw an exception, it runs through the first
part and then tells me that there are 0 instruments available.

Momo


try doing something with your exception rather than throwing it away.

A Java program that I've written that makes sounds works fine when I
test it with appletviewer, but not when I use a browser (Firefox or
Explorer). The difference is that when I call the MidiSystem
synthesizer with getAvailableInstruments, I get a bunch of instruments
(411) when running it with appletviewer, but none when using a browser.
Why the difference? A short program that demonstrates my problem is
below.

import javax.swing.*;
import javax.sound.midi.*;
public class SimpleSound extends JApplet
{
public void init()
{
try {
Synthesizer synth=MidiSystem.getSynthesizer();
synth.open();
Instrument[] instr=synth.getAvailableInstruments();
JOptionPane.showMessageDialog(null,"instr.length="+instr.length);
}
catch (MidiUnavailableException e) {
}
}
 
Joined
Nov 2, 2011
Messages
1
Reaction score
0
similar issue

I had a similar issue building an executable jar file. The application would find the MIDI instruments when running to Eclipse, but would return instruments of zero length when running outside of Eclipse.

It turned out that the two applications were running ot two different installed versions of the JRE. One of the versions of the JRE came without a default synthesizer sound bank. The file soundbank.gm was missing from the lib/audio folder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top