Java Code Examples for javax.sound.sampled.Clip#isActive()

The following examples show how to use javax.sound.sampled.Clip#isActive() . 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: ClipIsRunningAfterStop.java    From dragonwell8_jdk with GNU General Public License v2.0 7 votes vote down vote up
private static void test() throws Exception {
    // Will run the test no more than 15 seconds
    long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(15);
    while (failed == null && endtime - System.nanoTime() > 0) {
        Clip clip = createClip();
        clip.loop(Clip.LOOP_CONTINUOUSLY);
        clip.stop();
        if (clip.isRunning()) {
            if (clip.isRunning()) {
                throw new RuntimeException("Clip is running");
            }
        }
        if (clip.isActive()) {
            if (clip.isActive()) {
                throw new RuntimeException("Clip is active");
            }
        }
        clip.close();
    }
}
 
Example 2
Source File: ClipIsRunningAfterStop.java    From TencentKona-8 with GNU General Public License v2.0 7 votes vote down vote up
private static void test() throws Exception {
    // Will run the test no more than 15 seconds
    long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(15);
    while (failed == null && endtime - System.nanoTime() > 0) {
        Clip clip = createClip();
        clip.loop(Clip.LOOP_CONTINUOUSLY);
        clip.stop();
        if (clip.isRunning()) {
            if (clip.isRunning()) {
                throw new RuntimeException("Clip is running");
            }
        }
        if (clip.isActive()) {
            if (clip.isActive()) {
                throw new RuntimeException("Clip is active");
            }
        }
        clip.close();
    }
}
 
Example 3
Source File: ClipIsRunningAfterStop.java    From openjdk-jdk8u with GNU General Public License v2.0 7 votes vote down vote up
private static void test() throws Exception {
    // Will run the test no more than 15 seconds
    long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(15);
    while (failed == null && endtime - System.nanoTime() > 0) {
        Clip clip = createClip();
        clip.loop(Clip.LOOP_CONTINUOUSLY);
        clip.stop();
        if (clip.isRunning()) {
            if (clip.isRunning()) {
                throw new RuntimeException("Clip is running");
            }
        }
        if (clip.isActive()) {
            if (clip.isActive()) {
                throw new RuntimeException("Clip is active");
            }
        }
        clip.close();
    }
}
 
Example 4
Source File: ClipIsRunningAfterStop.java    From jdk8u_jdk with GNU General Public License v2.0 7 votes vote down vote up
private static void test() throws Exception {
    // Will run the test no more than 15 seconds
    long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(15);
    while (failed == null && endtime - System.nanoTime() > 0) {
        Clip clip = createClip();
        clip.loop(Clip.LOOP_CONTINUOUSLY);
        clip.stop();
        if (clip.isRunning()) {
            if (clip.isRunning()) {
                throw new RuntimeException("Clip is running");
            }
        }
        if (clip.isActive()) {
            if (clip.isActive()) {
                throw new RuntimeException("Clip is active");
            }
        }
        clip.close();
    }
}
 
Example 5
Source File: IsRunningHang.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 6
Source File: ChangingBuffer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean doMixerClip(Mixer mixer, AudioFormat format) {
    if (mixer==null) return false;
    try {
        System.out.println("Trying mixer "+mixer+":");
            DataLine.Info info = new DataLine.Info(
                                      Clip.class,
                                      format,
                                      (int) samplerate);

            Clip clip = (Clip) mixer.getLine(info);
        System.out.println("  - got clip: "+clip);
        System.out.println("  - open with format "+format);
        clip.open(format, buffer, 0, buffer.length);
        System.out.println("  - playing...");
        clip.start();
        System.out.println("  - waiting while it's active...");
        while (clip.isActive())
                Thread.sleep(100);
        System.out.println("  - waiting 100millis");
        Thread.sleep(100);
        System.out.println("  - drain1");
        clip.drain();
        System.out.println("  - drain2");
        clip.drain();
        System.out.println("  - stop");
        clip.stop();
        System.out.println("  - close");
        clip.close();
        System.out.println("  - closed");
    } catch (Throwable t) {
        System.out.println("  - Caught exception. Not failed.");
        System.out.println("  - "+t.toString());
        return false;
    }
    return true;
}
 
Example 7
Source File: MultiClip.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Stops the clip, if active.
 */
public void stop() {
	try {
		Clip clip = getClip();
		if (clip == null)
			return;

		if (clip.isActive())
			clip.stop();
	} catch (LineUnavailableException e) {}
}