javax.sound.sampled.LineListener Java Examples

The following examples show how to use javax.sound.sampled.LineListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiClip.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: SoftMixingDataLine.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #3
Source File: SoftMixingMixer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #4
Source File: SoftMixingDataLine.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #5
Source File: AbstractLine.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
Example #6
Source File: AbstractLine.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
Example #7
Source File: SDLLinuxCrash.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #8
Source File: SoftMixingMixer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #9
Source File: SoftMixingDataLine.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #10
Source File: SoftMixingDataLine.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #11
Source File: ClipPlayer.java    From FxDock with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example #12
Source File: SoundController.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example #13
Source File: SoftMixingMixer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #14
Source File: SoftMixingMixer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #15
Source File: AbstractLine.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
Example #16
Source File: AbstractLine.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
Example #17
Source File: AbstractLine.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public final void addLineListener(LineListener listener) {
    synchronized(listeners) {
        if ( ! (listeners.contains(listener)) ) {
            listeners.addElement(listener);
        }
    }
}
 
Example #18
Source File: SoftMixingDataLine.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #19
Source File: SoftMixingMixer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.remove(listener);
    }
}
 
Example #20
Source File: SoftMixingDataLine.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public final void removeLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
Example #21
Source File: AudioPlayer.java    From Java-Speech-Recognizer-Tutorial--Calculator with Apache License 2.0 4 votes vote down vote up
/**
 * @param ais
 * @param line
 * @param lineListener
 */
public AudioPlayer(AudioInputStream ais, SourceDataLine line, LineListener lineListener) {
	this.ais = ais;
	this.line = line;
	this.lineListener = lineListener;
}
 
Example #22
Source File: DummySourceDataLine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void addLineListener(LineListener listener) {
}
 
Example #23
Source File: SoftMixingDataLine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public final void removeLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
Example #24
Source File: DummySourceDataLine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void addLineListener(LineListener listener) {
}
 
Example #25
Source File: DummySourceDataLine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
}
 
Example #26
Source File: SoftMixingDataLine.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public final void addLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
Example #27
Source File: SoftMixingDataLine.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public final void addLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
Example #28
Source File: DummySourceDataLine.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
}
 
Example #29
Source File: SoftMixingMixer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void addLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}
 
Example #30
Source File: SoftMixingMixer.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.remove(listener);
    }
}