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();
}
}
java类javax.sound.sampled.LineEvent.Type的实例源码
Sound.java 文件源码
项目:EnchantedForest
阅读 35
收藏 0
点赞 0
评论 0
VentanaInternaGrabador.java 文件源码
项目:Sistemas-Multimedia
阅读 23
收藏 0
点赞 0
评论 0
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();
}
VentanaInternaReproductor.java 文件源码
项目:Sistemas-Multimedia
阅读 18
收藏 0
点赞 0
评论 0
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();
}
VentanaInternaGrabador.java 文件源码
项目:Sistemas-Multimedia
阅读 21
收藏 0
点赞 0
评论 0
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();
}
VentanaInternaReproductor.java 文件源码
项目:Sistemas-Multimedia
阅读 22
收藏 0
点赞 0
评论 0
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();
}
}
JavaDefaultSoundManager.java 文件源码
项目:monkey-shines-java-port
阅读 20
收藏 0
点赞 0
评论 0
/**
*
* 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);
}
}
}
JSAudio.java 文件源码
项目:Amber-IDE
阅读 22
收藏 0
点赞 0
评论 0
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();
}
});
}
}
});
}
TelegraphSound.java 文件源码
项目:mars-sim
阅读 21
收藏 0
点赞 0
评论 0
/**
* 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();
}
}
AchievementSound.java 文件源码
项目:agui_framework
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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();
}
}
Sound.java 文件源码
项目:EnchantedForest
阅读 27
收藏 0
点赞 0
评论 0
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();
}
}
PulseAudioFixerListener.java 文件源码
项目:opsu
阅读 22
收藏 0
点赞 0
评论 0
@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();
}
});
}
}
Audio.java 文件源码
项目:UniversityCP
阅读 35
收藏 0
点赞 0
评论 0
@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();
}
Audio.java 文件源码
项目:UniversityCP
阅读 23
收藏 0
点赞 0
评论 0
@Override
public synchronized void update(LineEvent event) {
Type eventType = event.getType();
if (eventType == Type.STOP || eventType == Type.CLOSE) {
done = true;
notifyAll();
}
}
JavaDefaultSoundManager.java 文件源码
项目:monkey-shines-java-port
阅读 24
收藏 0
点赞 0
评论 0
@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
);
}
JavaDefaultSoundManager.java 文件源码
项目:monkey-shines-java-port
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
}
JSAudio.java 文件源码
项目:Amber-IDE
阅读 21
收藏 0
点赞 0
评论 0
public void setVolume(float volume) {
((FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
}