JDK-5070730 : REGRESSION: play method audioclip
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.2,5.0,6
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_98,windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2004-07-01
  • Updated: 2005-11-15
  • Resolved: 2005-02-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other JDK 6
5.0u2 b07Fixed 6Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: gm110360			Date: 07/01/2004


FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Windows xp

A DESCRIPTION OF THE PROBLEM :
audioclip play method does not work. but loop method does.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
play any .au file using
audioClip ac;
ac = JApplet.newAudioClip(url of au file));
ac.play() // does not work;
ac.loop() works;

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
sound should play
ACTUAL -
sound does not play

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.applet.*;
import java.net.*;

public class Bug{
    public static void main(String[] args) {

        AudioClip ac=Applet.newAudioClip(Bug.class.getResource("yes.au"));
        ac.play();
        // ac.loop();
    }
}

This I can compile.
I need a "0.au" file in the same directory as the Bug class file.

While running

C:\j2sdk1.4.2_03\jre\bin\java.exe Bug
plays the sound

"C:\Program Files\Java\jre1.5.0\bin\java.exe" Bug
does not play the sound
---------- END SOURCE ----------

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 281874) 
======================================================================
###@###.### 2004-07-02

Comments
EVALUATION Don't see the test. ###@###.### 2004-07-01 java.applet.AppletAudioClip which is used in the test is a simple wrapper for com.sun.media.sound.JavaSoundAudioClip, here is rewritten test which use this class directly and demostrate the problem. --- Bug.java --- import java.applet.*; import java.net.*; import com.sun.media.sound.JavaSoundAudioClip; public class Bug{ public static void main(String[] args) { try { JavaSoundAudioClip ac = new JavaSoundAudioClip(Bug.class.getResource("yes.au").openStream()); ac.play(); } catch (Exception e3) { System.err.println("Failed to construct the AudioClip: " + e3); } } } --- end of Bug.java --- Thus this is java sound's problem, not applet's one. ###@###.### 2004-09-17 This might be either java sound or io problem, reassigning to javasound for further investigation. ###@###.### 2004-09-17 ###@###.### 2005-2-10 01:15:36 GMT The simplified testcase differs from the incidents on the JavaMedia forum. It works on 1.4.2 because of a bug that does not terminate the JVM when the program ends, see CR 4735740. If delay is added to the testcase it works on 1.5.0. Most of the incidents on the forum indicate short audio clips are not played while the program / applet continues. A boundary condition exists in PLATFORM_API_WinOS_DirectSound.cpp in src/windows/native/com/sun/media/sound/engine/ that is frequently hit on very small files. Silence is played instead of the audio clip. ###@###.### 2005-2-18 03:12:32 GMT Trying to verify the fix on 1.5.0_02 B07 and B08 but the following code will not play the complete clip and the JVM will exit while playing it. AudioClip ac = Applet.newAudioClip(Bug.class.getResource("spacemusic.au"); //The following play() will not play the whole audio clip unless Thread.sleep(delay) is introduced after it. ac.play(); //And JVM will exit before loop() method to complete the audio clip unless Thread.sleep(delay) after it. ac.loop(); ###@###.### 2005-2-28 22:36:44 GMT As mentioned above, simplified testcase differs from the incidents on the JavaMedia forum. It ONLY works on 1.4.2 because of a bug that does not terminate the JVM when the program ends, see CR 4735740. AudioClip.play() is asynchronous; it starts playing audio, it returns as soon as the clip is started, it does not delay the current thread to the end of the clip. Since the fix fo CR 4735740 is in 1.5.0, the delay is needed in the testcase following ac.play(). ###@###.### 2005-3-01 01:09:18 GMT Users may run into problem when they cannot query the length of the audio clip at runtime, hence, do not know how long the delay is needed for the sleep. ###@###.### 2005-03-01 18:26:56 GMT AudioClip is not intended for the type of program that needs to know how long the clip is in order to wait for it. If it is absolutely necessary to wait for a clip to complete, the addLineListener function can be used to associate an event listener that can be executed when the clip completes playing. The intent of AudioClip is to allow a programmer to trigger a sound when an event occurs without having to manage play of the clip. For instance in a game when an object collides with a wall the programmer may want to start a collision sound, change the object's trajectory, possibly indicate damage to the object or the wall and go back to the main loop of the game. In another case, say to simulate a car alarm, the programmer may want to trigger a looping clip until an event occurs that would clear the alarm; at that time the programmer would invoke stop() on the clip. an. ###@###.### 2005-03-01 19:11:35 GMT
2005-03-01

SUGGESTED FIX In src/windows/native/com/sun/media/sound/engine/ change PLATFORM_API_WinOS_DirectSound.cpp 557c557 < if (start < (int) playCursor && end > (int) playCursor) { --- > if (start <= (int) playCursor && end > (int) playCursor) { ###@###.### 2005-2-18 03:12:32 GMT
2005-02-18