Opening instruments with appletviewer vs. browser

Discussion in 'Java' started by Momo, Jan 26, 2007.

  1. Momo

    Momo Guest

    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) {
    }
    }
    }
    Momo, Jan 26, 2007
    #1
    1. Advertising

  2. On Jan 27, 5:04 am, "Momo" <> wrote:
    > A Java ..


    Please cross-post rather than multi-post, in future.

    (X-post to c.l.j.h./p., w/f-u to c.l.j.h. only)

    Andrew T.
    Andrew Thompson, Jan 27, 2007
    #2
    1. Advertising

  3. Momo

    Guest

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


    On Jan 26, 10:04 am, "Momo" <> wrote:
    > 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) {
    > }
    > }
    >
    > }
    , Jan 29, 2007
    #3
  4. Momo

    Momo Guest

    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


    On Jan 29, 12:25 am, wrote:
    > try doing something with your exception rather than throwing it away.
    >
    > On Jan 26, 10:04 am, "Momo" <> wrote:
    >
    > > 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) {
    > > }
    > > }

    >
    > > }
    Momo, Jan 31, 2007
    #4
  5. Momo

    mic1

    Joined:
    Nov 2, 2011
    Messages:
    1
    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.
    mic1, Nov 2, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CHANGE username to westes

    Sample Code That Instruments Java Byte Code?

    CHANGE username to westes, Oct 14, 2003, in forum: Java
    Replies:
    1
    Views:
    1,000
    Robert Olofsson
    Oct 14, 2003
  2. Roedy Green
    Replies:
    5
    Views:
    3,705
    Roedy Green
    Jul 15, 2007
  3. jeffbruce
    Replies:
    1
    Views:
    2,248
    travishein
    Aug 22, 2008
  4. Asbjørn Bjørnstad
    Replies:
    0
    Views:
    427
    Asbjørn Bjørnstad
    Oct 9, 2008
  5. Replies:
    0
    Views:
    731
Loading...

Share This Page