/**
* playback start method extended by some gui stuff
*/
@Override
public void play() {
try {
super.play();
} catch (LineUnavailableException | IOException e) {
e.printStackTrace();
}
panel[2].setText("\u25A0");
panel[2].setBackground(new Color(232, 232, 232));
// listen to the audioClip and when it is finished playing, trigger the stop() method to clean up and reset the button
LineListener listener = new LineListener() {
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
stop();
}
}
};
this.getAudioClip().addLineListener(listener);
}
java类javax.sound.sampled.LineEvent的实例源码
MeicoApp.java 文件源码
项目:meico
阅读 16
收藏 0
点赞 0
评论 0
AbstractLine.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractLine.java 文件源码
项目:jdk8u-jdk
阅读 19
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractDataLine.java 文件源码
项目:openjdk-jdk10
阅读 26
收藏 0
点赞 0
评论 0
/**
* This method sets the started state and generates
* events if it changes.
*/
final void setStarted(boolean started) {
if (Printer.trace) Printer.trace("> AbstractDataLine: setStarted(" + started + ")");
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.started != started) {
this.started = started;
sendEvents = true;
}
}
if (sendEvents) {
if (started) {
sendEvents(new LineEvent(this, LineEvent.Type.START, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.STOP, position));
}
}
if (Printer.trace) Printer.trace("< AbstractDataLine: setStarted completed");
}
AbstractLine.java 文件源码
项目:openjdk-jdk10
阅读 15
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
IsRunningHang.java 文件源码
项目:openjdk-jdk10
阅读 20
收藏 0
点赞 0
评论 0
private static void test(final AudioFormat format, final byte[] data)
throws Exception {
final Line.Info info = new DataLine.Info(Clip.class, format);
final Clip clip = (Clip) AudioSystem.getLine(info);
go = new CountDownLatch(1);
clip.addLineListener(event -> {
if (event.getType().equals(LineEvent.Type.START)) {
go.countDown();
}
});
clip.open(format, data, 0, data.length);
clip.start();
go.await();
while (clip.isRunning()) {
// This loop should not hang
}
while (clip.isActive()) {
// This loop should not hang
}
clip.close();
}
ClipLinuxCrash2.java 文件源码
项目:openjdk-jdk10
阅读 18
收藏 0
点赞 0
评论 0
public void update(LineEvent e) {
if (e.getType() == LineEvent.Type.STOP) {
stopOccured++;
out(" Test program: receives STOP event for clip="+clip.toString()+" no."+stopOccured);
out(" Test program: Calling close() in event dispatcher thread");
clip.close();
synchronized (lock) {
lock.notifyAll();
}
}
else if (e.getType() == LineEvent.Type.CLOSE) {
out(" Test program: receives CLOSE event for "+clip.toString());
synchronized (lock) {
lock.notifyAll();
}
}
else if (e.getType() == LineEvent.Type.START) {
out(" Test program: receives START event for "+clip.toString());
}
else if (e.getType() == LineEvent.Type.OPEN) {
out(" Test program: receives OPEN event for "+clip.toString());
}
}
AudioClip.java 文件源码
项目:Mafia
阅读 22
收藏 0
点赞 0
评论 0
public void playAudio(float volumeDelta) {
boolean isPlaying = false;
if(clip != null)
if(clip.isActive())
isPlaying = true;
if(!shouldPreloadAudio && !isPlaying) {
loadClip();
clip.addLineListener((LineEvent event) -> {
if(event.getType() == LineEvent.Type.STOP)
clip.close();
});
}
float newVolume = Math.max(Math.min(volumeAdjustment + volumeDelta, volume.getMaximum()), volume.getMinimum());
volume.setValue(newVolume);
clip.setFramePosition(0);
clip.start();
}
BufferedAudio.java 文件源码
项目:SimpleAudio
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void open() throws AudioException {
try {
this.audioInputStream = Audio.getAudioInputStream(this.resource);
this.clip = AudioSystem.getClip();
this.clip.open(this.audioInputStream);
this.clip.addLineListener(event -> {
if(event.getType().equals(LineEvent.Type.STOP) && this.clip.getMicrosecondPosition() >= this.clip.getMicrosecondLength()) {
this.trigger(AudioEvent.Type.REACHED_END);
}
});
this.controls = AbstractAudio.extractControls(this.clip, this.controls);
this.open = true;
this.trigger(AudioEvent.Type.OPENED);
} catch(Exception exception) {
throw new AudioException(exception);
}
}
AbstractLine.java 文件源码
项目:openjdk9
阅读 18
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractLine.java 文件源码
项目:jdk8u_jdk
阅读 19
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractLine.java 文件源码
项目:lookaside_java-1.8.0-openjdk
阅读 18
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
Audio.java 文件源码
项目:neo
阅读 23
收藏 0
点赞 0
评论 0
/**
* <strong><em>playSound</em></strong><br /><br />
*
*  Plays a .wav audio file located in /res/audio/.<br />
*  <em>E.g.</em> <sub>audio</sub><br /><br />
*  File location would be: <sub>/res/audio/audio.wav</sub><br />
*  and would be played automatically.
*
* @param audio - File name.
*/
public void playSound(String audio){
try{
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(
getClass().getResource("/audio/"+audio+".wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
clip.addLineListener(new LineListener() {
@Override
public void update(LineEvent arg0) {
if(arg0.getFramePosition()==clip.getFrameLength()){
clip.close();
}
}
});
clips.put(audio, clip);
}catch(Exception e){
e.printStackTrace();
}
}
Sound.java 文件源码
项目:WorldGrower
阅读 26
收藏 0
点赞 0
评论 0
private Clip openClip(boolean closeAfterPlaying) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
AudioInputStream audioStream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(audioFilePath));
DataLine.Info info = getLineInfo(audioStream);
Clip audioClip = (Clip) AudioSystem.getLine(info);
if (closeAfterPlaying) {
audioClip.addLineListener(new LineListener() {
@Override
public void update(LineEvent myLineEvent) {
if (myLineEvent.getType() == LineEvent.Type.STOP)
audioClip.close();
}
});
}
audioClip.open(audioStream);
return audioClip;
}
Player.java 文件源码
项目:MakamBox
阅读 26
收藏 0
点赞 0
评论 0
public void setPlayer(Wavefile af) throws Exception{
clip = af.getClip();
clip.open();
fullLength = clip.getFrameLength();
endPoint = fullLength;
gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
playing = false;
clip.addLineListener(new LineListener(){
@Override
public void update(LineEvent arg0) {
while(playing){
int tempframe = clip.getFramePosition();
MakamBoxAnalysis.positionSlide.setValue(tempframe);
if (stopbutton!=null&&tempframe == fullLength){
stopbutton.doClick();
} else if(stopbutton!=null && tempframe>=endPoint){
playAgain();
} else if (tempframe == fullLength){
stop();
}
}
}
});
}
AbstractLine.java 文件源码
项目:infobip-open-jdk-8
阅读 23
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractLine.java 文件源码
项目:jdk8u-dev-jdk
阅读 20
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
UI.java 文件源码
项目:txtUML
阅读 24
收藏 0
点赞 0
评论 0
private void playSirenSound() {
try {
File soundFile = new File(sirenFile);
AudioInputStream soundIn = AudioSystem.getAudioInputStream(soundFile);
AudioFormat format = soundIn.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
clip = (Clip) AudioSystem.getLine(info);
clip.addLineListener(new LineListener() {
@Override
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
soundOn = false;
}
}
});
clip.open(soundIn);
clip.start();
soundOn = true;
} catch (Exception e) {
e.printStackTrace();
}
}
AbstractLine.java 文件源码
项目:jdk7-jdk
阅读 18
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
protected void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractLine.java 文件源码
项目:openjdk-source-code-learn
阅读 21
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
protected void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractLine.java 文件源码
项目:OLD-OpenJDK8
阅读 20
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
Process.java 文件源码
项目:maryspeak
阅读 27
收藏 0
点赞 0
评论 0
private void playAudio(AudioInputStream audio)
{
LineListener lineListener = new LineListener()
{
public void update(LineEvent event)
{
if (event.getType() == LineEvent.Type.START) { Log.print(Log.DEBUG,"Audio started playing."); }
else if (event.getType() == LineEvent.Type.STOP) { Log.print(Log.DEBUG,"Audio stopped playing."); }
else if (event.getType() == LineEvent.Type.OPEN) { Log.print(Log.DEBUG,"Audio line opened."); }
else if (event.getType() == LineEvent.Type.CLOSE) { Log.print(Log.DEBUG,"Audio line closed."); }
}
};
AudioPlayer ap = new AudioPlayer(audio, lineListener);
ap.start();
}
AudioPlay.java 文件源码
项目:crowdpp
阅读 18
收藏 0
点赞 0
评论 0
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.OPEN) {
// start the line, init the buffer
line.start();
int bytes = line.getBufferSize();
byteBuf = new byte [bytes];
doubleBuf = new double [bytes / af.getFrameSize()];
fs = af.getFrameSize();
lineOpened = true;
} else if (event.getType() == LineEvent.Type.START) {
// nothing to do here
} else if (event.getType() == LineEvent.Type.STOP) {
line.close();
} else if (event.getType() == LineEvent.Type.CLOSE) {
// only free the line now
lineOpened = false;
} else
System.err.println("Unknown LineEvent: " + event.getType());
}
RawCapturer.java 文件源码
项目:crowdpp
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void update(LineEvent le) {
if (!le.getLine().equals(line))
return;
System.err.println(new Date() + ": RawCapturer.update: " + le);
if (le.getType() == LineEvent.Type.START){
System.err.println("RawCapturer.update: notifyStart()");
notifyStart();
}
else if (le.getType() == LineEvent.Type.STOP){
System.err.println("RawCapturer.update: notifyStop()");
stopped = true;
notifyStop();
}
}
VentanaInternaGrabador.java 文件源码
项目:Sistemas-Multimedia
阅读 21
收藏 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
阅读 19
收藏 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
阅读 17
收藏 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
阅读 23
收藏 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();
}
}
AbstractLine.java 文件源码
项目:openjdk-jdk7u-jdk
阅读 22
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}
AbstractLine.java 文件源码
项目:openjdk-icedtea7
阅读 20
收藏 0
点赞 0
评论 0
/**
* This method sets the open state and generates
* events if it changes.
*/
final void setOpen(boolean open) {
if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
if (this.open != open) {
this.open = open;
sendEvents = true;
}
}
if (sendEvents) {
if (open) {
sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
} else {
sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
}
}
if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ") this.open: " + this.open);
}