Search in sources :

Example 1 with WAVLoader

use of com.jme3.audio.plugins.WAVLoader 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();
    }
}
Also used : OGGLoader(com.jme3.audio.plugins.OGGLoader) AssetInfo(com.jme3.asset.AssetInfo) AssetLoader(com.jme3.asset.AssetLoader) JFileChooser(javax.swing.JFileChooser) WAVLoader(com.jme3.audio.plugins.WAVLoader)

Aggregations

AssetInfo (com.jme3.asset.AssetInfo)1 AssetLoader (com.jme3.asset.AssetLoader)1 OGGLoader (com.jme3.audio.plugins.OGGLoader)1 WAVLoader (com.jme3.audio.plugins.WAVLoader)1 JFileChooser (javax.swing.JFileChooser)1