Hi there!
Thanks a lot to everyone writing/debugging/contributing with amazing code
I’m making a sound player app to browse some folders using Guido.
If the selected file is a .wav it loads it with
soundfile = new SoundFile(this, fileToLoad);
if the file is a .flac, I call a decoder function to convert it onto a .wav in a temp directory.
Decoder.decode(fileToLoad, tempFile);
Where fileToLoad is the selected file from the list, and tempFile is my temporary .wav file to write over.
The result is then loaded onto soundfile:
soundfile = new SoundFile(this, tempFile);
My problem is the following:
If I want to play two .flac files in a consecutive order, soundfile, doesn’t release the old one, so the decoder function can’t write over it.
And my question is:
Is there a way to tell soundfile to release the file?
The function I’m using to open fies:
public void openFile(String fileToLoad) {
if (soundfile!=null) {
soundfile.stop();
soundfile=null;
}
println(soundfile);
String fileExtension = fileToLoad.toLowerCase().substring(fileToLoad.length()-4);
if (fileExtension.equals(".wav")) {
soundfile = new SoundFile(this, fileToLoad);
} else if (fileExtension.equals("flac")) {
try {
Files.deleteIfExists(Paths.get(tempFile));
}
catch (Exception e) {
System.out.println("Problem with deleting file");
e.printStackTrace();
}
try {
Decoder.decode(fileToLoad, tempFile);
}
catch (Exception e) {
System.out.println("Problem decoding file");
e.printStackTrace();
}
soundfile = new SoundFile(this, tempFile);
} else if (!(fileExtension.equals("flac")&&!fileExtension.equals(".wav"))) {
println("unsupported file format");
}
return;
}