use of com.jme3.audio.plugins.OGGLoader 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