Clip soundToPlay = loadSound(soundFile); if (soundToPlay!=null){ soundToPlay.start(); }
final Clip soundToPlay = loadSound(soundFile); new Thread(){ public void run(){ if (soundToPlay!=null){ soundToPlay.start(); while (soundToPlay.isRunning()){ try { sleep(50); } catch (InterruptedException ex) { soundToPlay.stop(); interrupt(); } } soundToPlay.stop(); } } }.start();
    public void playSound(int sound){        try{            if (!PropertiesManager.getOptionsManager().isSoundEnabled()){                return;            }            File soundFile = null;            switch (sound){                case ABGEBROCHEN:{                    soundFile = new File(soundPath + "abgebrochen.wav");                    break;                }                case SUCHEN:{                    soundFile = new File(soundPath + "suchen.wav");                    break;                }                case VERBINDEN:{                    soundFile = new File(soundPath + "verbinden.wav");                    break;                }                case GESPEICHERT:{                    soundFile = new File(soundPath + "gespeichert.wav");                    break;                }                case KOMPLETT:{                    soundFile = new File(soundPath + "komplett.wav");                    break;                }                case LADEN:{                    soundFile = new File(soundPath + "laden.wav");                    break;                }                case POWER:{                    soundFile = new File(soundPath + "pwdl.wav");                    break;                }                case VERWEIGERT:{                    soundFile = new File(soundPath + "verweigert.wav");                    break;                }                case KONKRETISIEREN:{                    soundFile = new File(soundPath + "konkretisieren.wav");                    break;                }                case ZUGANG_GEWAEHRT:{                    soundFile = new File(soundPath + "zuganggestattet.wav");                    break;                }                case GESTARTET:{                    soundFile = new File(soundPath + "gestartet.wav");                    break;                }                default:                {                    logger.error("SoundPlayer::playSound() ungueltiger Parameter: " + sound);                }            }            Clip soundToPlay = loadSound(soundFile);            if (soundToPlay!=null){                soundToPlay.start();            }        }        catch(Exception e)        {            logger.error(e);        }    }