javax.sound.sampled.LineListener源码实例Demo

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

下面列出了javax.sound.sampled.LineListener 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: opsu-dance   文件: MultiClip.java
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
	Clip clip = getClip();
	if (clip == null)
		return;

	// PulseAudio does not support Master Gain
	if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
		// set volume
		FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
		float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
		gainControl.setValue(dB);
	}

	if (listener != null)
		clip.addLineListener(listener);
	clip.setFramePosition(0);
	clip.start();
}
 
源代码2 项目: jdk8u-jdk   文件: AbstractLine.java
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
源代码3 项目: openjdk-jdk9   文件: SDLLinuxCrash.java
public static SourceDataLine start() throws Exception {
    AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
    if (addLen) {
        staticLen+=(int) (staticLen/5)+1000;
    } else {
        staticLen-=(int) (staticLen/5)+1000;
    }
    if (staticLen>8*44100*4) {
        staticLen = 8*44100*4;
        addLen=!addLen;
    }
    if (staticLen<1000) {
        staticLen = 1000;
        addLen=!addLen;
    }
    int len = staticLen;
    len -= (len % 4);
    out("    preparing to play back "+len+" bytes == "+bytes2Ms(len, format)+"ms audio...");

    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
    SourceDataLine sdl = (SourceDataLine) AudioSystem.getLine(info);
    sdl.addLineListener(new LineListener() {
            public void update(LineEvent e) {
                if (e.getType() == LineEvent.Type.STOP) {
                    out("    calling close() from event dispatcher thread");
                    ((SourceDataLine) e.getSource()).close();
                }
                else if (e.getType() == LineEvent.Type.CLOSE) {
                }
            }
        });

    out("    opening...");
    sdl.open();
    out("    starting...");
    sdl.start();
    (new Thread(new SDLLinuxCrash(sdl, len))).start();
    return sdl;
}
 
源代码4 项目: openjdk-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);
    }
}
 
源代码5 项目: 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);
	}
}
 
源代码6 项目: opsu-dance   文件: SoundController.java
/**
 * Plays a sound clip.
 * @param clip the Clip to play
 * @param volume the volume [0, 1]
 * @param listener the line listener
 */
private static void playClip(MultiClip clip, float volume, LineListener listener) {
	if (clip == null)  // clip failed to load properly
		return;

       currentSoundComponent = clip;

	if (volume > 0f && !isMuted) {
		try {
			clip.start(volume, listener);
		} catch (LineUnavailableException e) {
			softErr(e, "Could not start clip %s", clip.getName());
		}
	}
}
 
源代码7 项目: jdk8u_jdk   文件: AbstractLine.java
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: AbstractLine.java
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
源代码9 项目: openjdk-8   文件: AbstractLine.java
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
源代码10 项目: hottub   文件: 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);
    }
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: 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);
    }
}
 
源代码12 项目: Bytecoder   文件: 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 项目: 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);
    }
}
 
源代码14 项目: Bytecoder   文件: 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);
    }
}
 
源代码15 项目: openjdk-8-source   文件: AbstractLine.java
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
源代码16 项目: openjdk-jdk9   文件: 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 项目: 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);
    }
}
 
源代码18 项目: openjdk-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);
    }
}
 
源代码19 项目: jdk8u-jdk   文件: DummySourceDataLine.java
public void addLineListener(LineListener listener) {
}
 
源代码20 项目: openjdk-8-source   文件: DummySourceDataLine.java
public void removeLineListener(LineListener listener) {
}
 
/**
 * @param ais
 * @param lineListener
 */
public AudioPlayer(AudioInputStream ais, LineListener lineListener) {
	this.ais = ais;
	this.lineListener = lineListener;
}
 
源代码22 项目: jdk8u-jdk   文件: SoftMixingDataLine.java
public final void addLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
源代码23 项目: openjdk-jdk9   文件: LineInfoNPE.java
public void removeLineListener(LineListener listener) {
}
 
源代码24 项目: dragonwell8_jdk   文件: DummySourceDataLine.java
public void removeLineListener(LineListener listener) {
}
 
源代码25 项目: dragonwell8_jdk   文件: DummySourceDataLine.java
public void addLineListener(LineListener listener) {
}
 
源代码26 项目: dragonwell8_jdk   文件: DummySourceDataLine.java
public void removeLineListener(LineListener listener) {
}
 
源代码27 项目: openjdk-jdk9   文件: bug6251460.java
static protected void test()
        throws LineUnavailableException, InterruptedException {
    DataLine.Info info = new DataLine.Info(Clip.class, format);
    Clip clip = (Clip)AudioSystem.getLine(info);
    final MutableBoolean clipStoppedEvent = new MutableBoolean(false);
    clip.addLineListener(new LineListener() {
        @Override
        public void update(LineEvent event) {
            if (event.getType() == LineEvent.Type.STOP) {
                synchronized (clipStoppedEvent) {
                    clipStoppedEvent.value = true;
                    clipStoppedEvent.notifyAll();
                }
            }
        }
    });
    clip.open(format, soundData, 0, soundData.length);

    long lengthClip = clip.getMicrosecondLength() / 1000;
    log("Clip length " + lengthClip + " ms");
    log("Playing...");
    for (int i=1; i<=LOOP_COUNT; i++) {
        long startTime = currentTimeMillis();
        log(" Loop " + i);
        clip.start();

        synchronized (clipStoppedEvent) {
            while (!clipStoppedEvent.value) {
                clipStoppedEvent.wait();
            }
            clipStoppedEvent.value = false;
        }

        long endTime = currentTimeMillis();
        long lengthPlayed = endTime - startTime;

        if (lengthClip > lengthPlayed + 20) {
            log(" ERR: Looks like sound didn't play: played " + lengthPlayed + " ms instead " + lengthClip);
            countErrors++;
        } else {
            log(" OK: played " + lengthPlayed + " ms");
        }
        clip.setFramePosition(0);

    }
    log("Played " + LOOP_COUNT + " times, " + countErrors + " errors detected.");
}
 
源代码28 项目: hottub   文件: SoftMixingDataLine.java
public final void removeLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
源代码29 项目: TencentKona-8   文件: SoftMixingDataLine.java
public final void removeLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
源代码30 项目: TencentKona-8   文件: SoftMixingMixer.java
public void addLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}