Пример #1
0
 public void openSound() {
   if (!sound.isOpen()) {
     try {
       AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundPath);
       sound = AudioSystem.getClip();
       sound.open(audioInputStream);
     } catch (Exception e) {
       System.out.println("The sound from file " + String.valueOf(soundPath) + "was not found!");
       System.out.println(e);
     }
   }
 }
Пример #2
0
 Sound(URL soundPath, float gain) {
   this.soundPath = soundPath;
   try {
     AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundPath);
     sound = AudioSystem.getClip();
     sound.open(audioInputStream);
     gainControl = (FloatControl) sound.getControl(FloatControl.Type.MASTER_GAIN);
     gainControl.setValue(gain);
   } catch (Exception e) {
     System.out.println("The sound from file " + String.valueOf(soundPath) + "was not found!");
     System.out.println(e);
   } // Satisfy the catch
 }
Пример #3
0
 public void dispose() {
   sound.close();
   sound = null;
 }
Пример #4
0
 public void restartSound() {
   sound.stop();
   sound.flush();
   sound.setFramePosition(0);
   sound.start();
 }
Пример #5
0
 public void pauseSound() {
   sound.stop();
 }
Пример #6
0
 public void playSound() {
   sound.start(); // Play only once
 }
Пример #7
0
 public void stopSound() {
   sound.stop(); // Stop and set the play position at the beginning
   sound.flush();
   sound.setFramePosition(0);
 }
Пример #8
0
 public void loopSound() {
   sound.loop(Clip.LOOP_CONTINUOUSLY); // Loop
 }
Пример #9
0
 public void closeSound() {
   sound.close();
 }