Mercurial > hg > pulseaudio
changeset 137:09bfaae2203b
2008-09-23 Omair Majid <omajid@redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
(ClipThread.run): The while loop doesnt end now if loop is less
0. Makes it work with LOOP_CONTINUOUSLY (-1).
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java
(testLoopContinuously): New function. Tests that loop(LOOP_CONTINUOUSLY)
works.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Tue, 23 Sep 2008 17:07:56 -0400 |
parents | c46f6e0e7959 |
children | 6409aaedc201 |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java |
diffstat | 2 files changed, 45 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Tue Sep 23 15:02:55 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Tue Sep 23 17:07:56 2008 -0400 @@ -81,7 +81,7 @@ @Override public void run() { - while (loopsLeft >= 0) { + while (true) { writeFrames(currentFrame, endFrame + 1); if (Thread.interrupted()) { // Thread.currentThread().interrupt();
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java Tue Sep 23 15:02:55 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java Tue Sep 23 17:07:56 2008 -0400 @@ -138,6 +138,50 @@ clip.close(); } + + + @Test + public void testLoopContinuously() throws LineUnavailableException, + IOException, UnsupportedAudioFileException, InterruptedException { + System.out + .println("This tests loop(LOOP_CONTINUOUSLY) on the Clip"); + final Clip clip = (Clip) mixer.getLine(new Line.Info(Clip.class)); + File soundFile = new File("testsounds/error.wav"); + AudioInputStream audioInputStream = AudioSystem + .getAudioInputStream(soundFile); + clip.open(audioInputStream); + + clip.setLoopPoints((int) (clip.getFrameLength() / 4), (int) (clip + .getFrameLength() / 2)); + clip.loop(Clip.LOOP_CONTINUOUSLY); + + Runnable blocker = new Runnable() { + + @Override + public void run() { + clip.drain(); + } + + }; + + Thread th = new Thread(blocker); + th.start(); + th.join(10000); + + if (!th.isAlive()) { + clip.close(); + Assert.fail("LOOP_CONTINUOUSLY doesnt seem to work"); + } + + clip.stop(); + th.join(500); + if ( th.isAlive()) { + clip.close(); + Assert.fail("stopping LOOP_CONTINUOSLY failed"); + } + + clip.close(); + } @Test public void testIsActiveAndIsOpen() throws LineUnavailableException,