use of com.jme3.audio.AudioData in project jmonkeyengine by jMonkeyEngine.
the class WAVLoader method load.
private AudioData load(AssetInfo info, InputStream inputStream, boolean stream) throws IOException {
this.in = new ResettableInputStream(info, inputStream);
inOffset = 0;
int sig = in.readInt();
if (sig != i_RIFF)
throw new IOException("File is not a WAVE file");
// skip size
in.readInt();
if (in.readInt() != i_WAVE)
throw new IOException("WAVE File does not contain audio");
inOffset += 4 * 3;
readStream = stream;
if (readStream) {
audioStream = new AudioStream();
audioData = audioStream;
} else {
audioBuffer = new AudioBuffer();
audioData = audioBuffer;
}
while (true) {
int type = in.readInt();
int len = in.readInt();
inOffset += 4 * 2;
switch(type) {
case i_fmt:
readFormatChunk(len);
inOffset += len;
break;
case i_data:
// Compute duration based on data chunk size
duration = (float) (len / bytesPerSec);
if (readStream) {
readDataChunkForStream(inOffset, len);
} else {
readDataChunkForBuffer(len);
}
return audioData;
default:
int skipped = in.skipBytes(len);
if (skipped <= 0) {
return null;
}
inOffset += skipped;
break;
}
}
}
use of com.jme3.audio.AudioData 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