本文整理了Java中javax.sound.sampled.Clip.addLineListener()
方法的一些代码示例,展示了Clip.addLineListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clip.addLineListener()
方法的具体详情如下:
包路径:javax.sound.sampled.Clip
类名称:Clip
方法名:addLineListener
暂无
代码示例来源:origin: RipMeApp/ripme
/**
* Plays a sound from a file.
*
* @param filename Path to the sound file
*/
public static void playSound(String filename) {
URL resource = ClassLoader.getSystemClassLoader().getResource(filename);
try {
final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
clip.addLineListener(event -> {
if (event.getType() == LineEvent.Type.STOP) {
clip.close();
}
});
clip.open(AudioSystem.getAudioInputStream(resource));
clip.start();
} catch (Exception e) {
LOGGER.error("Failed to play sound " + filename, e);
}
}
代码示例来源:origin: tomighty/tomighty
private SoundChain play(final Sound sound, boolean repeatedly, final SoundChain chain) {
stop(sound);
if(sound.disabled()) {
chain.takeOver();
return chain;
}
try {
InputStream stream = sound.inputStream();
//wrap the stream in another one that supports mark/reset (see issue #31)
stream = new BufferedInputStream(stream);
AudioInputStream input = AudioSystem.getAudioInputStream(stream);
Clip clip = AudioSystem.getClip();
clip.addLineListener(new ClipHandler(sound, chain));
clip.open(input);
if(repeatedly) {
clip.loop(Clip.LOOP_CONTINUOUSLY);
} else {
clip.start();
}
activeClips.put(sound, clip);
} catch (Exception e) {
logger.error("Error while playing sound: " + sound, e);
}
return chain;
}
代码示例来源:origin: libetl/soundtransform
private LineListener addLineListener (final Clip clip, final Object stopMonitor) {
final LineListener lineListener = new LineListener () {
@Override
public void update (final LineEvent event) {
final LineEvent.Type type = event.getType ();
if (type == LineEvent.Type.STOP) {
synchronized (clip) {
if (stopMonitor != null) {
synchronized (stopMonitor) {
stopMonitor.notifyAll ();
}
}
if (event.getFramePosition () != -1) {
clip.stop ();
clip.close ();
clip.notifyAll ();
}
}
}
}
};
clip.addLineListener (lineListener);
return lineListener;
}
代码示例来源:origin: ddf/Minim
c.addLineListener( new LineListener()
代码示例来源:origin: stackoverflow.com
// ...
protected File soundFile;
protected Clip clip;
protected LineListener listener;
public void play() {
soundFile = new File(DIR_SOUND + audiotitle);
AudioInputStream in = AudioSystem.getAudioInputStream(soundFile);
clip = AudioSystem.getClip();
clip.addLineListener(listener);
clip.open(in);
clip.start();
// ...
}
// ...
代码示例来源:origin: stackoverflow.com
public static void play(String name) {
try{
AudioInputStream sounds = AudioSystem.getAudioInputStream(Buzzer.class.getResource(name));
final Clip clip = AudioSystem.getClip();
clip.addLineListener(new LineListener() {
public void update(LineEvent e) {
LineEvent.Type type = e.getType();
if(type == type.STOP) clip.close();
}
});
clip.open(sounds);
clip.start();
} catch(Exception e){
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
public void playClip() throws Exception {
final CountDownLatch playingFinished = new CountDownLatch(1);
final Clip clip = (Clip) AudioSystem.getLine(...);
clip.open(...);
clip.addLineListener(new LineListener() {
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
event.getLine().close();
playingFinished.countDown();
}
}
});
clip.start();
try {
playingFinished.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
代码示例来源:origin: stackoverflow.com
clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(new File("go.wav")));
clip.addLineListener(new LineListener() {
public void update(LineEvent event) {
if(event.getType() == LineEvent.Type.STOP){
代码示例来源:origin: Multibit-Legacy/multibit-hd
/**
* @param name The name of the sound file (no extension)
*/
private static void play(String name) {
Preconditions.checkState(allSounds.containsKey(name), "'" + name + "' must be present (did you initialise?)");
byte[] sound = allSounds.get(name);
try {
final Clip clip = AudioSystem.getClip();
clip.addLineListener(new LineListener() {
@Override
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP)
clip.close();
}
});
clip.open(AudioSystem.getAudioInputStream(new ByteArrayInputStream(sound)));
clip.start();
} catch (UnsupportedAudioFileException e) {
throw new IllegalStateException(e.getMessage());
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());
} catch (LineUnavailableException e) {
throw new IllegalStateException(e.getMessage());
}
}
代码示例来源:origin: gradle.plugin.com.fractalwrench/PingPlugin
synchronized void play(InputStream inputStream) throws InterruptedException {
// convert the inputstream into an audioinputstream
try (BufferedInputStream bis = new BufferedInputStream(inputStream);
Clip clip = AudioSystem.getClip();
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(bis)) {
clip.open(audioInputStream);
clip.setFramePosition(0); // start at beginning of track
clip.addLineListener(this);
clip.start();
waitForPlaybackCompletion(); // block until at end of track
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: jcgay/maven-notifier
private void play(AudioInputStream ais) {
try {
Clip clip = AudioSystem.getClip();
EndListener listener = new EndListener();
clip.addLineListener(listener);
clip.open(ais);
playAndWait(clip, listener);
} catch (LineUnavailableException | IOException e) {
fail(e);
} finally {
IOUtil.close(ais);
}
}
代码示例来源:origin: stackoverflow.com
clip.open(sound);
clip.addLineListener(new LineListener() {
代码示例来源:origin: stackoverflow.com
clip.open(sound);
clip.addLineListener(new LineListener() {
代码示例来源:origin: stackoverflow.com
clip1.addLineListener(listener);
clip2.addLineListener(listener);
Runnable r = new Runnable() {
代码示例来源:origin: stackoverflow.com
clip.addLineListener(new LineListener() {
@Override
public void update(LineEvent event) {
代码示例来源:origin: cpesch/RouteConverter
private void playNext(File file) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
synchronized (notificationMutex) {
playing = true;
}
CancelAction cancelAction = new CancelAction();
Application.getInstance().getContext().getNotificationManager().showNotification(
MessageFormat.format(Application.getInstance().getContext().getBundle().getString("play-voice-started"), file.getName()), cancelAction);
try (AudioInputStream inputStream = AudioSystem.getAudioInputStream(file)) {
clip = AudioSystem.getClip();
clip.addLineListener(clipListener);
clip.open(inputStream);
clip.start();
}
}
代码示例来源:origin: com.github.bloodshura/ignitium-core
clip.addLineListener(event -> {
if (event.getType() == LineEvent.Type.STOP) {
clip.close();
代码示例来源:origin: com.github.bloodshura/shurax
clip.addLineListener(event -> {
if (event.getType() == LineEvent.Type.STOP) {
clip.close();
代码示例来源:origin: br.com.jarch/jarch-utils
private static boolean play(final InputStream arquivo, int count) {
try (final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(arquivo)) {
// Carrega o formato do audio e cria uma linha
final AudioFormat audioFormat = audioInputStream.getFormat();
final DataLine.Info dataLineInfo = new DataLine.Info(Clip.class,
audioInputStream.getFormat(),
(int) audioInputStream.getFrameLength() * audioFormat.getFrameSize());
// Carrega o som para o dispositivo
try (final Clip clip = (Clip) AudioSystem.getLine(dataLineInfo)) {
// Evento do LineListener
clip.addLineListener(e -> {
if (LineEvent.Type.STOP.equals(e.getType())) {
e.getLine().close();
}
});
clip.open(audioInputStream);
clip.loop(count);
}
return true;
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
LogUtils.generate(e);
return false;
}
}
}
代码示例来源:origin: br.com.jarch/jarch-util
private static boolean play(final InputStream arquivo, int count) {
try (final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(arquivo)) {
// Carrega o formato do audio e cria uma linha
final AudioFormat audioFormat = audioInputStream.getFormat();
final DataLine.Info dataLineInfo = new DataLine.Info(Clip.class,
audioInputStream.getFormat(),
(int) audioInputStream.getFrameLength() * audioFormat.getFrameSize());
// Carrega o som para o dispositivo
try (final Clip clip = (Clip) AudioSystem.getLine(dataLineInfo)) {
// Evento do LineListener
clip.addLineListener(e -> {
if (LineEvent.Type.STOP.equals(e.getType())) {
e.getLine().close();
}
});
clip.open(audioInputStream);
clip.loop(count);
}
return true;
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
LogUtils.generate(e);
return false;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!