Results 1 to 6 of 6
- 11-19-2010, 03:14 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 22
- Rep Power
- 0
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!
- 11-19-2010, 06:20 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Could you please the complete code to see?
- 11-20-2010, 02:04 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 22
- Rep Power
- 0
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 }
- 11-20-2010, 03:08 PM #4
Do you get any exceptions shown in the Java console?
db
- 11-20-2010, 03:47 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 22
- Rep Power
- 0
Nothing in the Java console.
- 11-21-2010, 06:40 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Seems the code has nothing wrong. Are you sure that the applet code has no mistake?
Similar Threads
-
Sound in java applet - please help
By LinuxDev@Flanders in forum Java AppletsReplies: 3Last Post: 08-16-2010, 10:26 AM -
add sound to my applet
By anotsu in forum Java AppletsReplies: 4Last Post: 03-24-2008, 11:26 PM -
applet sound
By marco in forum Java AppletsReplies: 1Last Post: 09-28-2007, 10:31 PM -
Sound in applet Java
By toby in forum Java AppletsReplies: 1Last Post: 08-07-2007, 05:52 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks