Java 类javax.sound.sampled.LineEvent.Type 实例源码

项目:EnchantedForest    文件:Sound.java   
public static void playClip(File clipFile) throws IOException, 
  UnsupportedAudioFileException, LineUnavailableException, InterruptedException {
  class AudioListener implements LineListener {
    private boolean done = false;
    @Override public synchronized void update(LineEvent event) {
      Type eventType = event.getType();
      if (eventType == Type.STOP || eventType == Type.CLOSE) {
        done = true;
        notifyAll();
      }
    }
    public synchronized void waitUntilDone() throws InterruptedException {
      while (!done) { wait(); }
    }
  }
  AudioListener listener = new AudioListener();
  AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(clipFile);
  try {
    Clip clip = AudioSystem.getClip();
    clip.addLineListener(listener);
    clip.open(audioInputStream);
    try {
      clip.start();
      listener.waitUntilDone();
    } finally {
      clip.close();
    }
  } finally {
    audioInputStream.close();
  }
}
项目:Sistemas-Multimedia    文件:VentanaInternaGrabador.java   
public VentanaInternaGrabador(final File f) {
    initComponents();

    recorder = new SMSoundPlayerRecorder(f);
    this.setTitle(f.getName());
    LineListener lineListener = new LineListener() {
        @Override
        public void update(LineEvent event) {
            if (event.getType() == Type.START) {
                recorderButton.setEnabled(false);
                stopButton.setEnabled(true);
            }
            if (event.getType() == Type.STOP) {
                recorderButton.setEnabled(true);
                stopButton.setEnabled(false);
                VentanaInternaReproductor vir = new VentanaInternaReproductor(f);
                VentanaPrincipal.getEscritorio().add(vir);
                vir.setVisible(true);
            }

        }
    };
    ((SMSoundPlayerRecorder) recorder).setLineListener(lineListener);
    this.pack();
}
项目:Sistemas-Multimedia    文件:VentanaInternaReproductor.java   
public VentanaInternaReproductor(File f) {
    initComponents();

    player = new SMSoundPlayerRecorder(f);
    this.setTitle(f.getName());
    LineListener lineListener = new LineListener() {
        @Override
        public void update(LineEvent event) {
            if (event.getType() == Type.START) {
                play.setEnabled(false);
                stop.setEnabled(true);
            }
            if (event.getType() == Type.STOP) {
                play.setEnabled(true);
                play.setSelected(false);
                stop.setEnabled(false);
            }
        }
    };
    ((SMSoundPlayerRecorder)player).setLineListener(lineListener);
    this.pack();
}
项目:Sistemas-Multimedia    文件:VentanaInternaGrabador.java   
public VentanaInternaGrabador() {
    initComponents();
    exist=true;
    recorder = new SMSoundPlayerRecorder(new File("nuevo"));
    LineListener lineListener = new LineListener() {
        @Override
        public void update(LineEvent event) {
            if (event.getType() == Type.START) {
                recorderButton.setEnabled(false);
                stopButton.setEnabled(true);
            }
            if (event.getType() == Type.STOP) {
                recorderButton.setEnabled(true);
                stopButton.setEnabled(false);
            }

        }
    };
    ((SMSoundPlayerRecorder) recorder).setLineListener(lineListener);
    this.pack();
}
项目:Sistemas-Multimedia    文件:VentanaInternaReproductor.java   
public VentanaInternaReproductor(File f) {
    initComponents();
    if (f != null) {
        player = new SMSoundPlayer(f);
        this.setTitle(f.getName());
        LineListener lineListener = new LineListener() {
            @Override
            public void update(LineEvent event) {
                if (event.getType() == Type.START) {
                    play.setEnabled(false);
                    stop.setEnabled(true);
                }
                if (event.getType() == Type.STOP) {
                    play.setEnabled(true);
                    play.setSelected(false);
                    stop.setEnabled(false);
                }
            }
        };
        ((SMSoundPlayer) player).setLineListener(lineListener);
        this.pack();
    }
}
项目:monkey-shines-java-port    文件:JavaDefaultSoundManager.java   
/**
 * 
 * Automatically called on construction and game setting change to match clip volume to
 * user defined levels.
 * 
 * @param value
 *      percentage to set music volume to
 * 
 */
private void setSoundVolume(int value) {
    if (value == 0) {
        soundOff = true;
        return;
    }

    soundOff = false;

    float decibelLevelOffset = SoundUtils.resolveDecibelOffsetFromPercentage(value);
    System.out.println("Decibel offset for sound: " + decibelLevelOffset);
    for (GameSoundEffect effect : GameSoundEffect.values() ) {
        Optional<Clip> clip = sounds.get(effect);
        if (clip.isPresent() ) {
            FloatControl gainControl = (FloatControl)
                clip.get().getControl(FloatControl.Type.MASTER_GAIN);
            gainControl.setValue(decibelLevelOffset);
        }
    }
}
项目:Amber-IDE    文件:JSAudio.java   
JSAudio(AudioInputStream as) throws LineUnavailableException, IOException {
    Mixer mix = AudioIO.findMixer(as.getFormat());
    clip = (Clip) (mix != null ? mix.getLine(new Line.Info(Clip.class)) : AudioSystem.getLine(new Line.Info(Clip.class)));
    clip.open(as);
    clip.addLineListener(new LineListener() {
        public void update(LineEvent event) {
            if (loop && event.getType() == Type.STOP) {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        clip.start();
                    }
                });
            }
        }
    });
}
项目:mars-sim    文件:TelegraphSound.java   
/**
 * This method allows to be notified for each event while playing a
 * sound
 */
@Override
public synchronized void update(final LineEvent event) {
    final Type eventType = event.getType();
    if (eventType == Type.STOP || eventType == Type.CLOSE) {
        done = true;
        notifyAll();
    }
}
项目:agui_framework    文件:AchievementSound.java   
/**
 * This method allows to be notified for each event while playing a
 * sound
 */
@Override
public synchronized void update(LineEvent event) {
    Type eventType = event.getType();
    if (eventType == Type.STOP || eventType == Type.CLOSE) {
        done = true;
        notifyAll();
    }
}
项目:EnchantedForest    文件:Sound.java   
public static void playClip(File clipFile) throws IOException, 
  UnsupportedAudioFileException, LineUnavailableException, InterruptedException {
  class AudioListener implements LineListener {
    private boolean done = false;
    @Override public synchronized void update(LineEvent event) {
      Type eventType = event.getType();
      if (eventType == Type.STOP || eventType == Type.CLOSE) {
        done = true;
        notifyAll();
      }
    }
    public synchronized void waitUntilDone() throws InterruptedException {
      while (!done) { wait(); }
    }
  }
  AudioListener listener = new AudioListener();
  AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(clipFile);
  try {
    Clip clip = AudioSystem.getClip();
    clip.addLineListener(listener);
    clip.open(audioInputStream);
    try {
      clip.start();
      listener.waitUntilDone();
    } finally {
      clip.close();
    }
  } finally {
    audioInputStream.close();
  }
}
项目:opsu    文件:PulseAudioFixerListener.java   
@Override
public void update(LineEvent event) {
    if (event.getType().equals(Type.STOP)) {
        // Stop must be called in a separate thread in order for the
        // underflow callback to complete and not deadlock.
        executor.execute(new Runnable() {
            @Override
            public void run() {
                clip.stop();
            }
        });
    }
}
项目:UniversityCP    文件:Audio.java   
@Override
public void interrupt() {
    if (this.line != null && this.line.isOpen() && this.listener != null)
        this.listener.update(
                new LineEvent(this.line, Type.STOP, AudioSystem.NOT_SPECIFIED)
        );
    super.interrupt();
}
项目:UniversityCP    文件:Audio.java   
@Override
public synchronized void update(LineEvent event) {
    Type eventType = event.getType();
    if (eventType == Type.STOP || eventType == Type.CLOSE) {
        done = true;
        notifyAll();
    }
}
项目:monkey-shines-java-port    文件:JavaDefaultSoundManager.java   
@Override public void playOnceDelayed(
        final GameSoundEffect effect, 
        final int delay, 
        final TimeUnit unit) {

    if (soundOff)  return;

    holdSound(effect);

    delaySound.schedule(
        new Runnable() { 
            @Override public void run() { 
                playOnce(effect);
                // Block this scheduled thread until sound is over
                Optional<Clip> clip = sounds.get(effect);
                if (clip.isPresent() ) {
                    clip.get().addLineListener(new LineListener() {
                        @Override public void update(LineEvent event) {
                            if (event.getType() == Type.STOP) {
                                releaseSound(effect);
                            }
                        }
                    });
                }
            } 
        }, 
        delay,
        unit
    );
}
项目:monkey-shines-java-port    文件:JavaDefaultSoundManager.java   
/**
 * Automatically called on construction and game setting change to match clip volume to
 * user defined levels. Does nothing if there is no background music
 * 
 * @param value
 *      percentage to set music volume to
 */
private void setMusicVolume(int value) {
    if (bgm.isPresent() ) {
        Clip mus = bgm.get();
        if (value == 0) {
            musicOff = true;
            // unlike sounds, music must manually be shut off, and then back on again if required.
            if (mus.isRunning() ) {
                musicCut = true;
                mus.stop();
            }
            return;
        } else {
            // if the music was previously cut because it was already running, then and only then do
            // we resume it.
            if (musicCut) {
                musicCut = false;
                mus.start();
            }
        }

        if (bgm.isPresent() ) {
            musicOff = false;
            FloatControl gainControl = (FloatControl) bgm.get().getControl(FloatControl.Type.MASTER_GAIN);
            float decibelLevelOffset = SoundUtils.resolveDecibelOffsetFromPercentage(value);
            // Music seems to be naturally louder than sound effects, so give it a negative nudge.
            decibelLevelOffset -= 10;
            System.out.println("Decibel offset for music: " + decibelLevelOffset);
            gainControl.setValue(decibelLevelOffset);
        } else {
            musicOff = true;
        }
    }
}
项目:Amber-IDE    文件:JSAudio.java   
public void setVolume(float volume) {
    ((FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
}