类javax.sound.sampled.LineEvent源码实例Demo

下面列出了怎么用javax.sound.sampled.LineEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: AbstractLine.java
/**
 * 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);
}
 
源代码2 项目: TencentKona-8   文件: AbstractLine.java
/**
 * 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);
}
 
源代码3 项目: openjdk-jdk8u   文件: AbstractLine.java
/**
 * 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);
}
 
源代码4 项目: ripme   文件: Utils.java
/**
 * 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);
    }
}
 
源代码5 项目: Bytecoder   文件: AbstractDataLine.java
/**
 * This method sets the started state and generates
 * events if it changes.
 */
final void setStarted(boolean 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));
        }
    }
}
 
源代码6 项目: txtUML   文件: UI.java
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();
	}
}
 
源代码7 项目: openjdk-jdk9   文件: AbstractLine.java
/**
 * 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);
}
 
源代码8 项目: openjdk-jdk9   文件: IsRunningHang.java
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();
}
 
源代码9 项目: openjdk-jdk9   文件: ClipLinuxCrash2.java
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());
    }
}
 
源代码10 项目: jdk8u-jdk   文件: AbstractLine.java
/**
 * 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);
}
 
源代码11 项目: dragonwell8_jdk   文件: AbstractDataLine.java
/**
 * 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 (Printer.debug) Printer.debug("    AbstractDataLine: setStarted: this.started: " + this.started);
        //if (Printer.debug) Printer.debug("                                  started: " + started);

        if (this.started != started) {
            this.started = started;
            sendEvents = true;
        }
    }

    //if (Printer.debug) Printer.debug("                                  this.started: " + this.started);
    //if (Printer.debug) Printer.debug("                                  sendEvents: " + sendEvents);

    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");
}
 
源代码12 项目: dragonwell8_jdk   文件: SoftMixingDataLine.java
final void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码13 项目: dragonwell8_jdk   文件: SoftMixingMixer.java
private void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码14 项目: javagame   文件: WaveEngine.java
public void update(LineEvent event) {
    // �X�g�b�v���Ō�܂ōĐ����ꂽ�ꍇ
    if (event.getType() == LineEvent.Type.STOP) {
        Clip clip = (Clip) event.getSource();
        clip.stop();
        clip.setFramePosition(0); // �Đ��ʒu���ŏ��ɖ߂�
    }
}
 
源代码15 项目: TencentKona-8   文件: SoftMixingDataLine.java
final void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码16 项目: TencentKona-8   文件: SoftMixingMixer.java
private void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码17 项目: jdk8u60   文件: AbstractDataLine.java
/**
 * 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 (Printer.debug) Printer.debug("    AbstractDataLine: setStarted: this.started: " + this.started);
        //if (Printer.debug) Printer.debug("                                  started: " + started);

        if (this.started != started) {
            this.started = started;
            sendEvents = true;
        }
    }

    //if (Printer.debug) Printer.debug("                                  this.started: " + this.started);
    //if (Printer.debug) Printer.debug("                                  sendEvents: " + sendEvents);

    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");
}
 
源代码18 项目: jdk8u60   文件: SoftMixingDataLine.java
final void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码19 项目: jdk8u60   文件: SoftMixingMixer.java
private void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码20 项目: Game   文件: soundPlayer.java
public static void playSoundFile(String key) {
	try {
		if (!mudclient.optionSoundDisabled) {
			File sound = mudclient.soundCache.get(key + ".wav");
			if (sound == null)
				return;
			try {
				// PC sound code:
				final Clip clip = AudioSystem.getClip();
				clip.addLineListener(myLineEvent -> {
					if (myLineEvent.getType() == LineEvent.Type.STOP)
						clip.close();
				});
				clip.open(AudioSystem.getAudioInputStream(sound));
				clip.start();

				// Android sound code:
				//int dataLength = DataOperations.getDataFileLength(key + ".pcm", soundData);
				//int offset = DataOperations.getDataFileOffset(key + ".pcm", soundData);
				//clientPort.playSound(soundData, offset, dataLength);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}

	} catch (RuntimeException var6) {
		throw GenUtil.makeThrowable(var6, "client.SC(" + "dummy" + ',' + (key != null ? "{...}" : "null") + ')');
	}
}
 
源代码21 项目: petscii-bbs   文件: DefaultSoundEffect.java
/**
 * {@inheritDoc}
 */
public void update(final LineEvent e) {
  
  if (e.getType() == LineEvent.Type.STOP) {

    notifySoundStopped();
  }
}
 
源代码22 项目: openjdk-jdk8u   文件: AbstractDataLine.java
/**
 * 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 (Printer.debug) Printer.debug("    AbstractDataLine: setStarted: this.started: " + this.started);
        //if (Printer.debug) Printer.debug("                                  started: " + started);

        if (this.started != started) {
            this.started = started;
            sendEvents = true;
        }
    }

    //if (Printer.debug) Printer.debug("                                  this.started: " + this.started);
    //if (Printer.debug) Printer.debug("                                  sendEvents: " + sendEvents);

    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");
}
 
源代码23 项目: openjdk-jdk8u   文件: SoftMixingDataLine.java
final void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码24 项目: FxDock   文件: ClipPlayer.java
public static void play(InputStream in)
{
	try
	{
		AudioInputStream stream = AudioSystem.getAudioInputStream(in);
		AudioFormat format = stream.getFormat();
		DataLine.Info info = new DataLine.Info(Clip.class, format);
		
		final Clip clip = (Clip)AudioSystem.getLine(info);
		clip.addLineListener(new LineListener()
		{
			public void update(LineEvent ev)
			{
				LineEvent.Type t = ev.getType();
				if(t == LineEvent.Type.STOP)
				{
					clip.close();
				}
			}
		});
		clip.open(stream);
		clip.start();
	}
	catch(Exception e)
	{
		Log.err(e);
	}
}
 
源代码25 项目: JVoiceXML   文件: AudioFilePlayer.java
/**
 * {@inheritDoc}
 */
@Override
public void update(final LineEvent event) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("line updated: " + event.getType());
    }

    if ((event.getType() == LineEvent.Type.CLOSE)
            || (event.getType() == LineEvent.Type.STOP)) {
        sem.release();
    }
}
 
源代码26 项目: Lunar   文件: Sound.java
@Override
public void update(LineEvent event) {
    LineEvent.Type type = event.getType();
    if (type == LineEvent.Type.STOP) {
        clip.close();
    }
}
 
源代码27 项目: openjdk-jdk8u-backup   文件: AbstractDataLine.java
/**
 * 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 (Printer.debug) Printer.debug("    AbstractDataLine: setStarted: this.started: " + this.started);
        //if (Printer.debug) Printer.debug("                                  started: " + started);

        if (this.started != started) {
            this.started = started;
            sendEvents = true;
        }
    }

    //if (Printer.debug) Printer.debug("                                  this.started: " + this.started);
    //if (Printer.debug) Printer.debug("                                  sendEvents: " + sendEvents);

    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");
}
 
源代码28 项目: jdk8u_jdk   文件: SoftMixingDataLine.java
final void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码29 项目: openjdk-jdk8u-backup   文件: SoftMixingDataLine.java
final void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}
 
源代码30 项目: jdk8u_jdk   文件: SoftMixingMixer.java
private void sendEvent(LineEvent event) {
    if (listeners.size() == 0)
        return;
    LineListener[] listener_array = listeners
            .toArray(new LineListener[listeners.size()]);
    for (LineListener listener : listener_array) {
        listener.update(event);
    }
}