Results 1 to 6 of 6
  1. #1
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Smile No sound when applet is in browser

    I have an applet that I have been devloping in NetBeans. It works perfect in there. When I take the applet, and put it in the browser, it does not play sound. Specifically I am trying to play a midi note through the synthesizer. Here is a code snippet below:

    synth = MidiSystem.getSynthesizer();
    synth.open();
    MidiChannel[] channels = synth.getChannels();
    channel = channels[nChannelNumber];
    channel.noteOn(noteNumber, velocity);

    No errors are thrown. Log looks normal. Just wont play a sound.

    Thanks in advance!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Smile Posted Code

    Here is the most simplified version of my program. The midi note should play on load. It works in Netbeans, but not my browser. Thanks!

    Java Code:
    package midiprojectjavacode;
    
    import javax.sound.midi.MidiSystem;
    import javax.sound.midi.Synthesizer;
    import javax.sound.midi.MidiChannel;
    import javax.sound.midi.MidiUnavailableException;
    
    public class TestSandbox extends javax.swing.JApplet {
    
       //For playing notes on synthesizer
       Synthesizer	synth = null;
       public static MidiChannel	channel = null;
       int nChannelNumber = 1;
    
        /** Initializes the applet TestSandbox */
        public void init() {
            try {
                java.awt.EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        initComponents();
                        playMidiNoise();
                    }
                });
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
        public void playMidiNoise()
        {
            try
            {
                synth = MidiSystem.getSynthesizer();
                synth.open();
                MidiChannel[] channels = synth.getChannels();
                channel = channels[nChannelNumber];
                channel.noteOn(60, 50);
            }
            catch (MidiUnavailableException e)
            {
                System.out.println("Error getting/opening Sythesizer: + e");
            }
    
        }
    
        /** This method is called from within the init() method to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
        }// </editor-fold>
    
    
        // Variables declaration - do not modify
        // End of variables declaration
    
    }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default

    Do you get any exceptions shown in the Java console?

    db

  5. #5
    Ambergahill is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default

    Nothing in the Java console.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Sound in java applet - please help
    By LinuxDev@Flanders in forum Java Applets
    Replies: 3
    Last Post: 08-16-2010, 11:26 AM
  2. add sound to my applet
    By anotsu in forum Java Applets
    Replies: 4
    Last Post: 03-25-2008, 12:26 AM
  3. applet sound
    By marco in forum Java Applets
    Replies: 1
    Last Post: 09-28-2007, 11:31 PM
  4. Sound in applet Java
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 06:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •