Explorar el Código

AudioTrack : prevented audio track to be looped even if the channel loopMode is dontLoop

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9866 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
rem..om hace 13 años
padre
commit
a61bdf1d47
Se han modificado 1 ficheros con 47 adiciones y 28 borrados
  1. 47 28
      engine/src/core/com/jme3/animation/AudioTrack.java

+ 47 - 28
engine/src/core/com/jme3/animation/AudioTrack.java

@@ -44,18 +44,19 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.logging.Logger;
 
 
 /**
 /**
- * AudioTrack is a track to add to an existing animation, to paly a sound during an animations
- * for example : gun shot, foot step, shout, etc...
- * 
- * usage is 
+ * AudioTrack is a track to add to an existing animation, to paly a sound during
+ * an animations for example : gun shot, foot step, shout, etc...
+ *
+ * usage is
  * <pre>
  * <pre>
  * AnimControl control model.getControl(AnimControl.class);
  * AnimControl control model.getControl(AnimControl.class);
  * AudioTrack track = new AudioTrack(existionAudioNode, control.getAnim("TheAnim").getLength());
  * AudioTrack track = new AudioTrack(existionAudioNode, control.getAnim("TheAnim").getLength());
  * control.getAnim("TheAnim").addTrack(track);
  * control.getAnim("TheAnim").addTrack(track);
  * </pre>
  * </pre>
- * 
- * This is mostly intended for short sounds, playInstance will be called on the AudioNode at time 0 + startOffset. 
- * 
+ *
+ * This is mostly intended for short sounds, playInstance will be called on the
+ * AudioNode at time 0 + startOffset.
+ *
  *
  *
  * @author Nehon
  * @author Nehon
  */
  */
@@ -76,7 +77,6 @@ public class AudioTrack implements ClonableTrack {
         }
         }
 
 
         public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
         public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
-            stop();
         }
         }
     }
     }
 
 
@@ -88,8 +88,10 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * Creates an AudioTrack
      * Creates an AudioTrack
+     *
      * @param audio the AudioNode
      * @param audio the AudioNode
-     * @param length the length of the track (usually the length of the animation you want to add the track to)
+     * @param length the length of the track (usually the length of the
+     * animation you want to add the track to)
      */
      */
     public AudioTrack(AudioNode audio, float length) {
     public AudioTrack(AudioNode audio, float length) {
         this.audio = audio;
         this.audio = audio;
@@ -99,9 +101,12 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * Creates an AudioTrack
      * Creates an AudioTrack
+     *
      * @param audio the AudioNode
      * @param audio the AudioNode
-     * @param length the length of the track (usually the length of the animation you want to add the track to)
-     * @param startOffset the time in second when the sound will be played after the animation starts (default is 0)
+     * @param length the length of the track (usually the length of the
+     * animation you want to add the track to)
+     * @param startOffset the time in second when the sound will be played after
+     * the animation starts (default is 0)
      */
      */
     public AudioTrack(AudioNode audio, float length, float startOffset) {
     public AudioTrack(AudioNode audio, float length, float startOffset) {
         this(audio, length);
         this(audio, length);
@@ -110,10 +115,15 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * Internal use only
      * Internal use only
-     * @see Track#setTime(float, float, com.jme3.animation.AnimControl, com.jme3.animation.AnimChannel, com.jme3.util.TempVars) 
+     *
+     * @see Track#setTime(float, float, com.jme3.animation.AnimControl,
+     * com.jme3.animation.AnimChannel, com.jme3.util.TempVars)
      */
      */
     public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
     public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
 
 
+        if (time == length) {
+            return;
+        }
         if (!initialized) {
         if (!initialized) {
             control.addListener(new OnEndListener());
             control.addListener(new OnEndListener());
             initialized = true;
             initialized = true;
@@ -132,6 +142,7 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * Retruns the length of the track
      * Retruns the length of the track
+     *
      * @return length of the track
      * @return length of the track
      */
      */
     public float getLength() {
     public float getLength() {
@@ -140,7 +151,8 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * Clone this track
      * Clone this track
-     * @return 
+     *
+     * @return
      */
      */
     @Override
     @Override
     public Track clone() {
     public Track clone() {
@@ -148,8 +160,11 @@ public class AudioTrack implements ClonableTrack {
     }
     }
 
 
     /**
     /**
-     * This method clone the Track and search for the cloned counterpart of the original audio node in the given cloned spatial.
-     * The spatial is assumed to be the Spatial holding the AnimControl controling the animation using this Track.
+     * This method clone the Track and search for the cloned counterpart of the
+     * original audio node in the given cloned spatial. The spatial is assumed
+     * to be the Spatial holding the AnimControl controling the animation using
+     * this Track.
+     *
      * @param spatial the Spatial holding the AnimControl
      * @param spatial the Spatial holding the AnimControl
      * @return the cloned Track with proper reference
      * @return the cloned Track with proper reference
      */
      */
@@ -167,14 +182,15 @@ public class AudioTrack implements ClonableTrack {
 
 
         //setting user data on the new AudioNode and marking it with a reference to the cloned Track.
         //setting user data on the new AudioNode and marking it with a reference to the cloned Track.
         setUserData(audioTrack);
         setUserData(audioTrack);
-      
+
         return audioTrack;
         return audioTrack;
     }
     }
 
 
     /**
     /**
      * recursive function responsible for finding the newly cloned AudioNode
      * recursive function responsible for finding the newly cloned AudioNode
+     *
      * @param spat
      * @param spat
-     * @return 
+     * @return
      */
      */
     private AudioNode findAudio(Spatial spat) {
     private AudioNode findAudio(Spatial spat) {
         if (spat instanceof AudioNode) {
         if (spat instanceof AudioNode) {
@@ -213,16 +229,15 @@ public class AudioTrack implements ClonableTrack {
     }
     }
 
 
     public void cleanUp() {
     public void cleanUp() {
-       TrackInfo t = (TrackInfo) audio.getUserData("TrackInfo");
-       t.getTracks().remove(this);
-       if(!t.getTracks().isEmpty()){
-           audio.setUserData("TrackInfo", null);
-       }
+        TrackInfo t = (TrackInfo) audio.getUserData("TrackInfo");
+        t.getTracks().remove(this);
+        if (!t.getTracks().isEmpty()) {
+            audio.setUserData("TrackInfo", null);
+        }
     }
     }
-    
-    
+
     /**
     /**
-     * 
+     *
      * @return the audio node used by this track
      * @return the audio node used by this track
      */
      */
     public AudioNode getAudio() {
     public AudioNode getAudio() {
@@ -231,7 +246,8 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * sets the audio node to be used for this track
      * sets the audio node to be used for this track
-     * @param audio 
+     *
+     * @param audio
      */
      */
     public void setAudio(AudioNode audio) {
     public void setAudio(AudioNode audio) {
         if (this.audio != null) {
         if (this.audio != null) {
@@ -243,7 +259,7 @@ public class AudioTrack implements ClonableTrack {
     }
     }
 
 
     /**
     /**
-     * 
+     *
      * @return the start offset of the track
      * @return the start offset of the track
      */
      */
     public float getStartOffset() {
     public float getStartOffset() {
@@ -252,7 +268,8 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * set the start offset of the track
      * set the start offset of the track
-     * @param startOffset 
+     *
+     * @param startOffset
      */
      */
     public void setStartOffset(float startOffset) {
     public void setStartOffset(float startOffset) {
         this.startOffset = startOffset;
         this.startOffset = startOffset;
@@ -260,6 +277,7 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * Internal use only serialization
      * Internal use only serialization
+     *
      * @param ex exporter
      * @param ex exporter
      * @throws IOException exception
      * @throws IOException exception
      */
      */
@@ -272,6 +290,7 @@ public class AudioTrack implements ClonableTrack {
 
 
     /**
     /**
      * Internal use only serialization
      * Internal use only serialization
+     *
      * @param im importer
      * @param im importer
      * @throws IOException Exception
      * @throws IOException Exception
      */
      */