use of de.gurkenlabs.litiengine.resources.SoundFormat in project litiengine by gurkenlabs.
the class Editor method importSounds.
private void importSounds(File... selectedFiles) {
for (File file : selectedFiles) {
try (InputStream stream = new FileInputStream(file.getAbsolutePath())) {
SoundFormat format = SoundFormat.get(FileUtilities.getExtension(file));
SoundResource resource = new SoundResource(new BufferedInputStream(stream), FileUtilities.getFileName(file.getName()), format);
this.getGameFile().getSounds().removeIf(x -> x.getName().equals(resource.getName()));
this.getGameFile().getSounds().add(resource);
log.log(Level.INFO, "imported sound {0}", new Object[] { resource.getName() });
} catch (IOException | UnsupportedAudioFileException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
}
use of de.gurkenlabs.litiengine.resources.SoundFormat in project litiengine by gurkenlabs.
the class AssetPanelItem method exportSound.
private void exportSound() {
if (!(this.getOrigin() instanceof SoundResource)) {
return;
}
SoundResource sound = (SoundResource) this.getOrigin();
SoundFormat format = sound.getFormat();
if (format == SoundFormat.UNSUPPORTED) {
return;
}
FileFilter filter = new FileNameExtensionFilter(format.toString() + " - Sound", format.toString());
try {
JFileChooser chooser;
String source = Editor.instance().getProjectPath();
chooser = new JFileChooser(source != null ? source : new File(".").getCanonicalPath());
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
chooser.setDialogTitle("Export Sound");
chooser.setFileFilter(filter);
chooser.addChoosableFileFilter(filter);
chooser.setSelectedFile(new File(sound.getName() + format.toFileExtension()));
int result = chooser.showSaveDialog(Game.window().getRenderComponent());
if (result == JFileChooser.APPROVE_OPTION) {
try (FileOutputStream fos = new FileOutputStream(chooser.getSelectedFile().toString())) {
fos.write(Codec.decode(sound.getData()));
log.log(Level.INFO, "exported sound {0} to {1}", new Object[] { sound.getName(), chooser.getSelectedFile() });
}
}
} catch (IOException ex) {
log.log(Level.SEVERE, ex.getMessage(), ex);
}
}
Aggregations