javax.sound.sampled.Clip#isActive ( )源码实例Demo

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

源代码1 项目: dragonwell8_jdk   文件: ClipIsRunningAfterStop.java
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();
    }
}
 
源代码2 项目: TencentKona-8   文件: ClipIsRunningAfterStop.java
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();
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: ClipIsRunningAfterStop.java
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();
    }
}
 
源代码4 项目: jdk8u_jdk   文件: ClipIsRunningAfterStop.java
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();
    }
}
 
源代码5 项目: 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();
}
 
源代码6 项目: openjdk-jdk9   文件: ChangingBuffer.java
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;
}
 
源代码7 项目: opsu   文件: MultiClip.java
/**
 * Stops the clip, if active.
 */
public void stop() {
	try {
		Clip clip = getClip();
		if (clip == null)
			return;

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