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 Project: opsu-dance   Author: yugecin   File: MultiClip.java    License: 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 Project: jdk8u-jdk   Author: lambdalab-mirror   File: AbstractLine.java    License: 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 #3
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: SDLLinuxCrash.java    License: 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 #4
Source Project: openjdk-8   Author: bpupadhyaya   File: SoftMixingMixer.java    License: 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 #5
Source Project: FxDock   Author: andy-goryachev   File: ClipPlayer.java    License: 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 #6
Source Project: opsu-dance   Author: yugecin   File: SoundController.java    License: 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 #7
Source Project: jdk8u_jdk   Author: JetBrains   File: AbstractLine.java    License: 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 #8
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: AbstractLine.java    License: 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 #9
Source Project: openjdk-8   Author: bpupadhyaya   File: AbstractLine.java    License: 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 #10
Source Project: hottub   Author: dsrg-uoft   File: SoftMixingDataLine.java    License: 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 #11
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SoftMixingMixer.java    License: 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 #12
Source Project: Bytecoder   Author: mirkosertic   File: SoftMixingDataLine.java    License: 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 #13
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: SoftMixingDataLine.java    License: 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 #14
Source Project: Bytecoder   Author: mirkosertic   File: SoftMixingMixer.java    License: 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 #15
Source Project: openjdk-8-source   Author: keerath   File: AbstractLine.java    License: 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 Project: openjdk-jdk9   Author: AdoptOpenJDK   File: SoftMixingMixer.java    License: 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 #17
Source Project: jdk8u_jdk   Author: JetBrains   File: SoftMixingDataLine.java    License: 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 #18
Source Project: openjdk-8   Author: bpupadhyaya   File: SoftMixingDataLine.java    License: 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 Project: jdk8u-jdk   Author: lambdalab-mirror   File: DummySourceDataLine.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void addLineListener(LineListener listener) {
}
 
Example #20
Source Project: openjdk-8-source   Author: keerath   File: DummySourceDataLine.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
}
 
Example #21
Source Project: Java-Speech-Recognizer-Tutorial--Calculator   Author: goxr3plus   File: AudioPlayer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param ais
 * @param lineListener
 */
public AudioPlayer(AudioInputStream ais, LineListener lineListener) {
	this.ais = ais;
	this.lineListener = lineListener;
}
 
Example #22
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: SoftMixingDataLine.java    License: 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 #23
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: LineInfoNPE.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
}
 
Example #24
Source Project: dragonwell8_jdk   Author: alibaba   File: DummySourceDataLine.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
}
 
Example #25
Source Project: dragonwell8_jdk   Author: alibaba   File: DummySourceDataLine.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void addLineListener(LineListener listener) {
}
 
Example #26
Source Project: dragonwell8_jdk   Author: alibaba   File: DummySourceDataLine.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void removeLineListener(LineListener listener) {
}
 
Example #27
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: bug6251460.java    License: GNU General Public License v2.0 4 votes vote down vote up
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.");
}
 
Example #28
Source Project: hottub   Author: dsrg-uoft   File: SoftMixingDataLine.java    License: 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 #29
Source Project: TencentKona-8   Author: Tencent   File: SoftMixingDataLine.java    License: 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 #30
Source Project: TencentKona-8   Author: Tencent   File: SoftMixingMixer.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void addLineListener(LineListener listener) {
    synchronized (control_mutex) {
        listeners.add(listener);
    }
}