本文整理汇总了Java中javax.sound.sampled.LineEvent.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于javax.sound.sampled.LineEvent包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playClip
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
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();
}
}
示例2: VentanaInternaGrabador
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
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();
}
示例3: VentanaInternaReproductor
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
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();
}
示例4: VentanaInternaGrabador
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
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();
}
示例5: VentanaInternaReproductor
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
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();
}
}
示例6: setSoundVolume
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
/**
*
* 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);
}
}
}
示例7: JSAudio
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
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();
}
});
}
}
});
}
示例8: update
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
/**
* 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();
}
}
示例9: update
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
/**
* 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();
}
}
示例10: update
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
@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();
}
});
}
}
示例11: interrupt
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
@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();
}
示例12: update
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
@Override
public synchronized void update(LineEvent event) {
Type eventType = event.getType();
if (eventType == Type.STOP || eventType == Type.CLOSE) {
done = true;
notifyAll();
}
}
示例13: playOnceDelayed
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
@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
);
}
示例14: setMusicVolume
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
/**
* 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;
}
}
}
示例15: setVolume
import javax.sound.sampled.LineEvent.Type; //导入依赖的package包/类
public void setVolume(float volume) {
((FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume);
}