use of com.jme3.audio.AudioKey in project jmonkeyengine by jMonkeyEngine.
the class WAVLoader method load.
public Object load(AssetInfo info) throws IOException {
AudioData data;
InputStream inputStream = null;
try {
inputStream = info.openStream();
data = load(info, inputStream, ((AudioKey) info.getKey()).isStream());
if (data instanceof AudioStream) {
inputStream = null;
}
return data;
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
use of com.jme3.audio.AudioKey in project jmonkeyengine by jMonkeyEngine.
the class AudioNode method write.
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(audioKey, "audio_key", null);
oc.write(loop, "looping", false);
oc.write(volume, "volume", 1);
oc.write(pitch, "pitch", 1);
oc.write(timeOffset, "time_offset", 0);
oc.write(dryFilter, "dry_filter", null);
oc.write(velocity, "velocity", null);
oc.write(reverbEnabled, "reverb_enabled", false);
oc.write(reverbFilter, "reverb_filter", null);
oc.write(maxDistance, "max_distance", 20);
oc.write(refDistance, "ref_distance", 10);
oc.write(directional, "directional", false);
oc.write(direction, "direction", null);
oc.write(innerAngle, "inner_angle", 360);
oc.write(outerAngle, "outer_angle", 360);
oc.write(positional, "positional", false);
oc.write(velocityFromTranslation, "velocity_from_translation", false);
}
use of com.jme3.audio.AudioKey in project jmonkeyengine by jMonkeyEngine.
the class OGGLoader method load.
public Object load(AssetInfo info) throws IOException {
if (!(info.getKey() instanceof AudioKey)) {
throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey");
}
AudioKey key = (AudioKey) info.getKey();
boolean readStream = key.isStream();
boolean streamCache = key.useStreamCache();
InputStream in = null;
try {
in = info.openStream();
AudioData data = load(in, readStream, streamCache);
if (readStream && !streamCache) {
// we still need the stream in this case ..
in = null;
}
return data;
} finally {
if (in != null) {
in.close();
}
}
}
use of com.jme3.audio.AudioKey in project jmonkeyengine by jMonkeyEngine.
the class AudioNode method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
// to "audio_key" in case Spatial's key will be written as "key".
if (ic.getSavableVersion(AudioNode.class) == 0) {
audioKey = (AudioKey) ic.readSavable("key", null);
} else {
audioKey = (AudioKey) ic.readSavable("audio_key", null);
}
loop = ic.readBoolean("looping", false);
volume = ic.readFloat("volume", 1);
pitch = ic.readFloat("pitch", 1);
timeOffset = ic.readFloat("time_offset", 0);
dryFilter = (Filter) ic.readSavable("dry_filter", null);
velocity = (Vector3f) ic.readSavable("velocity", null);
reverbEnabled = ic.readBoolean("reverb_enabled", false);
reverbFilter = (Filter) ic.readSavable("reverb_filter", null);
maxDistance = ic.readFloat("max_distance", 20);
refDistance = ic.readFloat("ref_distance", 10);
directional = ic.readBoolean("directional", false);
direction = (Vector3f) ic.readSavable("direction", null);
innerAngle = ic.readFloat("inner_angle", 360);
outerAngle = ic.readFloat("outer_angle", 360);
positional = ic.readBoolean("positional", false);
velocityFromTranslation = ic.readBoolean("velocity_from_translation", false);
if (audioKey != null) {
try {
data = im.getAssetManager().loadAsset(audioKey);
} catch (AssetNotFoundException ex) {
Logger.getLogger(AudioNode.class.getName()).log(Level.FINE, "Cannot locate {0} for audio node {1}", new Object[] { audioKey, key });
data = PlaceholderAssets.getPlaceholderAudio();
}
}
}
use of com.jme3.audio.AudioKey in project jmonkeyengine by jMonkeyEngine.
the class TestMusicPlayer method btnOpenActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void btnOpenActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_btnOpenActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(true);
chooser.setDialogTitle("Select OGG file");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
btnStopActionPerformed(null);
final File selected = chooser.getSelectedFile();
AssetLoader loader = null;
if (selected.getName().endsWith(".wav")) {
loader = new WAVLoader();
} else {
loader = new OGGLoader();
}
AudioKey key = new AudioKey(selected.getName(), true, true);
try {
musicData = (AudioData) loader.load(new AssetInfo(null, key) {
@Override
public InputStream openStream() {
try {
return new FileInputStream(selected);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
});
} catch (IOException ex) {
ex.printStackTrace();
}
musicSource = new AudioNode(musicData, key);
musicLength = musicData.getDuration();
updateTime();
}
}
Aggregations