瀏覽代碼

Fix exception when stopping non-cached audio stream

shadowislord 10 年之前
父節點
當前提交
c7b6445a35

+ 4 - 0
jme3-core/src/main/java/com/jme3/audio/AudioStream.java

@@ -191,6 +191,10 @@ public class AudioStream extends AudioData implements Closeable {
             throw new RuntimeException("AudioStream is already closed!");
         }
     }
+    
+    public boolean isSeekable() {
+        return in instanceof SeekableStream;
+    }
 
     public void setTime(float time) {
         if (in instanceof SeekableStream) {

+ 8 - 1
jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java

@@ -1047,7 +1047,14 @@ public class ALAudioRenderer implements AudioRenderer, Runnable {
                 freeChannel(chan);
                 
                 if (src.getAudioData() instanceof AudioStream) {
-                    ((AudioStream)src.getAudioData()).setTime(0);
+                    // If the stream is seekable, then rewind it.
+                    // Otherwise, close it, as it is no longer valid.
+                    AudioStream stream = (AudioStream)src.getAudioData();
+                    if (stream.isSeekable()) {
+                        stream.setTime(0);
+                    } else {
+                        stream.close();
+                    }
                 }
             }
         }