Skip to content

Commit 9966505

Browse files
committed
Merge pull request #417 from MeFisto94/342
Simplified the AudioNode constructors (#342)
2 parents 9b7b363 + c900485 commit 9966505

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

jme3-core/src/main/java/com/jme3/audio/AudioNode.java

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2012, 2016 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -33,6 +33,7 @@
3333

3434
import com.jme3.asset.AssetManager;
3535
import com.jme3.asset.AssetNotFoundException;
36+
import com.jme3.audio.AudioData.DataType;
3637
import com.jme3.export.InputCapsule;
3738
import com.jme3.export.JmeExporter;
3839
import com.jme3.export.JmeImporter;
@@ -127,6 +128,17 @@ public AudioNode() {
127128
public AudioNode(AudioData audioData, AudioKey audioKey) {
128129
setAudioData(audioData, audioKey);
129130
}
131+
132+
/**
133+
* Creates a new <code>AudioNode</code> with the given audio file.
134+
* @param assetManager The asset manager to use to load the audio file
135+
* @param name The filename of the audio file
136+
* @param type The type. If <code>{@link com.jme3.audio.AudioData.DataType}.Stream</code>, the audio will be streamed gradually from disk,
137+
* otherwise it will be buffered (<code>{@link com.jme3.audio.AudioData.DataType}.Buffer</code>)
138+
*/
139+
public AudioNode(AssetManager assetManager, String name, DataType type) {
140+
this(assetManager, name, type == DataType.Stream, true);
141+
}
130142

131143
/**
132144
* Creates a new <code>AudioNode</code> with the given audio file.
@@ -139,6 +151,8 @@ public AudioNode(AudioData audioData, AudioKey audioKey) {
139151
* the stream cache is used. When enabled, the audio stream will
140152
* be read entirely but not decoded, allowing features such as
141153
* seeking, looping and determining duration.
154+
*
155+
* @deprecated Use {@link AudioNode#AudioNode(com.jme3.asset.AssetManager, java.lang.String, com.jme3.audio.AudioData.DataType)} instead
142156
*/
143157
public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) {
144158
this.audioKey = new AudioKey(name, stream, streamCache);
@@ -152,9 +166,11 @@ public AudioNode(AssetManager assetManager, String name, boolean stream, boolean
152166
* @param name The filename of the audio file
153167
* @param stream If true, the audio will be streamed gradually from disk,
154168
* otherwise, it will be buffered.
169+
*
170+
* @deprecated Use {@link AudioNode#AudioNode(com.jme3.asset.AssetManager, java.lang.String, com.jme3.audio.AudioData.DataType)} instead
155171
*/
156172
public AudioNode(AssetManager assetManager, String name, boolean stream) {
157-
this(assetManager, name, stream, false);
173+
this(assetManager, name, stream, true); // Always streamCached
158174
}
159175

160176
/**
@@ -167,17 +183,18 @@ public AudioNode(AssetManager assetManager, String name, boolean stream) {
167183
* @deprecated AudioRenderer parameter is ignored.
168184
*/
169185
public AudioNode(AudioRenderer audioRenderer, AssetManager assetManager, String name) {
170-
this(assetManager, name, false);
186+
this(assetManager, name, DataType.Buffer);
171187
}
172188

173189
/**
174190
* Creates a new <code>AudioNode</code> with the given audio file.
175191
*
176192
* @param assetManager The asset manager to use to load the audio file
177193
* @param name The filename of the audio file
194+
* @deprecated Use {@link AudioNode#AudioNode(com.jme3.asset.AssetManager, java.lang.String, com.jme3.audio.AudioData.DataType) } instead
178195
*/
179196
public AudioNode(AssetManager assetManager, String name) {
180-
this(assetManager, name, false);
197+
this(assetManager, name, DataType.Buffer);
181198
}
182199

183200
protected AudioRenderer getRenderer() {
@@ -310,6 +327,19 @@ public final void setStatus(AudioSource.Status status) {
310327
this.status = status;
311328
}
312329

330+
/**
331+
* Get the Type of the underlying AudioData to see if it's streamed or buffered.
332+
* This is a shortcut to getAudioData().getType()
333+
* <b>Warning</b>: Can return null!
334+
* @return The {@link com.jme3.audio.AudioData.DataType} of the audio node.
335+
*/
336+
public DataType getType() {
337+
if (data == null)
338+
return null;
339+
else
340+
return data.getDataType();
341+
}
342+
313343
/**
314344
* @return True if the audio will keep looping after it is done playing,
315345
* otherwise, false.

0 commit comments

Comments
 (0)