src/java.desktop/share/classes/com/sun/media/sound/JavaSoundAudioClip.java
changeset 51033 003aa3e59090
parent 50652 11f36b771afd
child 52248 2e330da7cbf4
equal deleted inserted replaced
51032:43ee4f1c333b 51033:003aa3e59090
   171         lastPlayCall = currentTime;
   171         lastPlayCall = currentTime;
   172 
   172 
   173         if (DEBUG || Printer.debug) Printer.debug("JavaSoundAudioClip.startImpl(loop="+loop+")");
   173         if (DEBUG || Printer.debug) Printer.debug("JavaSoundAudioClip.startImpl(loop="+loop+")");
   174         try {
   174         try {
   175             if (clip != null) {
   175             if (clip != null) {
   176                 if (!clip.isOpen()) {
   176                 // We need to disable autoclosing mechanism otherwise the clip
   177                     if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.open()");
   177                 // can be closed after "!clip.isOpen()" check, because of
   178                     clip.open(loadedAudioFormat, loadedAudio, 0, loadedAudioByteLength);
   178                 // previous inactivity.
   179                 } else {
   179                 clip.setAutoClosing(false);
   180                     if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.flush()");
   180                 try {
   181                     clip.flush();
   181                     if (!clip.isOpen()) {
   182                     if (loop != clipLooping) {
   182                         clip.open(loadedAudioFormat, loadedAudio, 0,
   183                         // need to stop in case the looped status changed
   183                                   loadedAudioByteLength);
   184                         if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.stop()");
   184                     } else {
   185                         clip.stop();
   185                         clip.flush();
       
   186                         if (loop != clipLooping) {
       
   187                             // need to stop in case the looped status changed
       
   188                             clip.stop();
       
   189                         }
   186                     }
   190                     }
       
   191                     clip.setFramePosition(0);
       
   192                     if (loop) {
       
   193                         clip.loop(Clip.LOOP_CONTINUOUSLY);
       
   194                     } else {
       
   195                         clip.start();
       
   196                     }
       
   197                     clipLooping = loop;
       
   198                 } finally {
       
   199                     clip.setAutoClosing(true);
   187                 }
   200                 }
   188                 clip.setFramePosition(0);
       
   189                 if (loop) {
       
   190                     if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.loop()");
       
   191                     clip.loop(Clip.LOOP_CONTINUOUSLY);
       
   192                 } else {
       
   193                     if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.start()");
       
   194                     clip.start();
       
   195                 }
       
   196                 clipLooping = loop;
       
   197                 if (DEBUG || Printer.debug)Printer.debug("Clip should be playing/looping");
       
   198 
       
   199             } else if (datapusher != null ) {
   201             } else if (datapusher != null ) {
   200                 datapusher.start(loop);
   202                 datapusher.start(loop);
   201                 if (DEBUG || Printer.debug)Printer.debug("Stream should be playing/looping");
   203                 if (DEBUG || Printer.debug)Printer.debug("Stream should be playing/looping");
   202 
   204 
   203             } else if (sequencer != null) {
   205             } else if (sequencer != null) {