G
Guest
Gast
Hi,ich habe in meiner Software einen Waveplayer integriert. Der Player geht auch super.
Leider stürzt der Player nach 5x drücken des Buttons "Sound An/Aus " ab!
Fehlermeldung:
xception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
at gui.WavePlayer.initPlayer(WavePlayer.java:42)
at gui.WavePlayer.startPlayer(WavePlayer.java:20)
at gui.ActionListener_MainSoftwareGUI.actionPerformed(ActionListener_MainSoftwareGUI.java:333)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Soundbutten im Listener:
private int soundzähler=0;
.
.
.
if(ae.getSource() == sound) {
if(soundzähler==0){
WavePlayer.startPlayer();
sound.setText("Sound AN");
soundzähler=1;
}
else{
WavePlayer.stopPlayer();
sound.setText("Sound Aus");
soundzähler=0;
}
Player:
import java.io.File;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.swing.JFrame;
public class WavePlayer extends JFrame {
//Attribute
public static Clip clip;
public static boolean running;
public static void startPlayer(){
initPlayer();
running = true;
clip.start();
clip.loop(-1);
}
public static void stopPlayer(){
running = false;
clip.stop();
}
//Methode
private static void initPlayer() {
try {
AudioInputStream ais =AudioSystem.getAudioInputStream(new File"./Sound.wav"));
AudioFormat format = ais.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format,
((int) ais.getFrameLength() * format.getFrameSize()));
clip = (Clip) AudioSystem.getLine(info);
clip.open(ais);
FloatControl gainControl = (FloatControl) clip
.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(1.0F);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Warum stürzt er beim 5x ab?
SoundAn - SoundAus -SoundAn - SoundAus -SoundAn - Absturz!!!!!!!!!!!!
Leider stürzt der Player nach 5x drücken des Buttons "Sound An/Aus " ab!
Fehlermeldung:
xception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
at gui.WavePlayer.initPlayer(WavePlayer.java:42)
at gui.WavePlayer.startPlayer(WavePlayer.java:20)
at gui.ActionListener_MainSoftwareGUI.actionPerformed(ActionListener_MainSoftwareGUI.java:333)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Soundbutten im Listener:
private int soundzähler=0;
.
.
.
if(ae.getSource() == sound) {
if(soundzähler==0){
WavePlayer.startPlayer();
sound.setText("Sound AN");
soundzähler=1;
}
else{
WavePlayer.stopPlayer();
sound.setText("Sound Aus");
soundzähler=0;
}
Player:
import java.io.File;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.swing.JFrame;
public class WavePlayer extends JFrame {
//Attribute
public static Clip clip;
public static boolean running;
public static void startPlayer(){
initPlayer();
running = true;
clip.start();
clip.loop(-1);
}
public static void stopPlayer(){
running = false;
clip.stop();
}
//Methode
private static void initPlayer() {
try {
AudioInputStream ais =AudioSystem.getAudioInputStream(new File"./Sound.wav"));
AudioFormat format = ais.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format,
((int) ais.getFrameLength() * format.getFrameSize()));
clip = (Clip) AudioSystem.getLine(info);
clip.open(ais);
FloatControl gainControl = (FloatControl) clip
.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(1.0F);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Warum stürzt er beim 5x ab?
SoundAn - SoundAus -SoundAn - SoundAus -SoundAn - Absturz!!!!!!!!!!!!