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

The following examples show how to use javax.sound.sampled.Clip#stop() . 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: WaveEngine.java    From javagame with MIT License 8 votes vote down vote up
public void update(LineEvent event) {
    // �X�g�b�v���Ō�܂ōĐ����ꂽ�ꍇ
    if (event.getType() == LineEvent.Type.STOP) {
        Clip clip = (Clip) event.getSource();
        clip.stop();
        clip.setFramePosition(0); // �Đ��ʒu���ŏ��ɖ߂�
    }
}
 
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 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 5
Source File: WaveEngine.java    From javagame with MIT License 7 votes vote down vote up
public void update(LineEvent event) {
    // �X�g�b�v���Ō�܂ōĐ����ꂽ�ꍇ
    if (event.getType() == LineEvent.Type.STOP) {
        Clip clip = (Clip) event.getSource();
        clip.stop();
        clip.setFramePosition(0); // �Đ��ʒu���ŏ��ɖ߂�
    }
}
 
Example 6
Source File: MultiClip.java    From opsu-dance with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Destroys the MultiClip and releases all resources.
 */
public void destroy() {
	if (clips.size() > 0) {
		for (Clip c : clips) {
			c.stop();
			c.flush();
			c.close();
		}
		extraClips -= clips.size() - 1;
		clips = new LinkedList<Clip>();
	}
	audioData = null;
	if (audioIn != null) {
		try {
			audioIn.close();
		} catch (IOException e) {
			softErr(e, "Failed to close MultiClip %s", name);
		}
	}
}
 
Example 7
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 8
Source File: MultiClip.java    From opsu with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Destroys the MultiClip and releases all resources.
 */
public void destroy() {
	if (clips.size() > 0) {
		for (Clip c : clips) {
			c.stop();
			c.flush();
			c.close();
		}
		extraClips -= clips.size() - 1;
		clips = new LinkedList<Clip>();
	}
	audioData = null;
	if (audioIn != null) {
		try {
			audioIn.close();
		} catch (IOException e) {
			ErrorHandler.error(String.format("Could not close AudioInputStream for MultiClip %s.", name), e, true);
		}
	}
}
 
Example 9
Source File: TestAudio.java    From Azzet with Open Software License 3.0 6 votes vote down vote up
private void doTest() throws AssetException, InterruptedException
{
	Clip clip = Assets.load("cowbell.wav");

	assertNotNull( clip );
	
	clip.start();

	Thread.sleep(1000);
	
	clip.stop();
	clip.close();
}
 
Example 10
Source File: WaveEngine.java    From javagame with MIT License 6 votes vote down vote up
public void update(LineEvent event) {
    // �X�g�b�v���Ō�܂ōĐ����ꂽ�ꍇ
    if (event.getType() == LineEvent.Type.STOP) {
        Clip clip = (Clip) event.getSource();
        clip.stop();
        clip.setFramePosition(0); // �Đ��ʒu���ŏ��ɖ߂�
    }
}
 
Example 11
Source File: WaveEngine.java    From javagame with MIT License 6 votes vote down vote up
public void update(LineEvent event) {
    // �X�g�b�v���Ō�܂ōĐ����ꂽ�ꍇ
    if (event.getType() == LineEvent.Type.STOP) {
        Clip clip = (Clip) event.getSource();
        clip.stop();
        clip.setFramePosition(0); // �Đ��ʒu���ŏ��ɖ߂�
    }
}
 
Example 12
Source File: WaveEngine.java    From javagame with MIT License 6 votes vote down vote up
public void update(LineEvent event) {
    // �X�g�b�v���Ō�܂ōĐ����ꂽ�ꍇ
    if (event.getType() == LineEvent.Type.STOP) {
        Clip clip = (Clip) event.getSource();
        clip.stop();
        clip.setFramePosition(0); // �Đ��ʒu���ŏ��ɖ߂�
    }
}
 
Example 13
Source File: WaveEngine.java    From javagame with MIT License 6 votes vote down vote up
public void update(LineEvent event) {
    // �X�g�b�v���Ō�܂ōĐ����ꂽ�ꍇ
    if (event.getType() == LineEvent.Type.STOP) {
        Clip clip = (Clip) event.getSource();
        clip.stop();
        clip.setFramePosition(0); // �Đ��ʒu���ŏ��ɖ߂�
    }
}
 
Example 14
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) {}
}
 
Example 15
Source File: WaveEngine.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void update(LineEvent event) {
	// If you stop playback or to the end
	if(event.getType() == LineEvent.Type.STOP) {
		Clip clip = (Clip) event.getSource();
		clip.stop();
		clip.setFramePosition(0); // Playback position back to the beginning
	}
}
 
Example 16
Source File: WaveEngine.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Stop
 * @param name Registered name
 */
public void stop(String name) {
	Clip clip = clipMap.get(name);

	if(clip != null) {
		clip.stop();
	}
}
 
Example 17
Source File: WaveEngine.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Playback
 * @param name Registered name
 */
public void play(String name) {
	Clip clip = clipMap.get(name);

	if(clip != null) {
		// Stop
		clip.stop();
		// Playback position back to the beginning
		clip.setFramePosition(0);
		// Playback
		clip.start();
	}
}
 
Example 18
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 19
Source File: ClickInPlay.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void play(Mixer mixer) {
    int res = 0;
    try {
        println("Getting clip from mixer...");
        source = (Clip) mixer.getLine(info);
        println("Opening clip...");
        source.open(audioFormat, audioData, 0, audioData.length);
        println("Starting clip...");
        source.loop(Clip.LOOP_CONTINUOUSLY);
        println("Now open your ears:");
        println("- if you hear a sine wave playing,");
        println("  listen carefully if you can hear clicks.");
        println("  If no, the bug is fixed.");
        println("- if you don't hear anything, it's possible");
        println("  that this mixer is not connected to an ");
        println("  amplifier, or that its volume is set to 0");
        key();
    } catch (IllegalArgumentException iae) {
        println("IllegalArgumentException: "+iae.getMessage());
        println("Sound device cannot handle this audio format.");
        println("ERROR: Test environment not correctly set up.");
        if (source!=null) {
            source.close();
            source = null;
        }
        return;
    } catch (LineUnavailableException lue) {
        println("LineUnavailableException: "+lue.getMessage());
        println("This is normal for some mixers.");
    } catch (Exception e) {
        println("Unexpected Exception: "+e.toString());
    }
    if (source != null) {
        println("Stopping...");
        source.stop();
        println("Closing...");
        source.close();
        println("Closed.");
        source = null;
    }
}
 
Example 20
Source File: ClipOpenBug.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    boolean res = true;
    try {
        AudioInputStream ais = new AudioInputStream(
                new ByteArrayInputStream(new byte[2000]),
                new AudioFormat(8000.0f, 8, 1, false, false), 2000); //
        AudioFormat format = ais.getFormat();
        DataLine.Info info = new DataLine.Info(Clip.class, format,
                                               ((int) ais.getFrameLength()
                                                        * format
                                                       .getFrameSize()));
        Clip clip = (Clip) AudioSystem.getLine(info);
        clip.open();
        FloatControl rateControl = (FloatControl) clip.getControl(
                FloatControl.Type.SAMPLE_RATE);
        int c = 0;
        while (c++ < 10) {
            clip.stop();
            clip.setFramePosition(0);
            clip.start();
            for (float frq = 22000; frq < 44100; frq = frq + 100) {
                try {
                    Thread.currentThread().sleep(20);
                } catch (Exception e) {
                    break;
                }
                rateControl.setValue(frq);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        res = ex.getMessage().indexOf(
                "This method should not have been invoked!") < 0;
    }
    if (res) {
        System.out.println("Test passed");
    } else {
        System.out.println("Test failed");
        throw new Exception("Test failed");
    }
}