Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created April 17, 2025 17:23
Show Gist options
  • Save thinkphp/066d6c4b49effee007196fee56b50ebf to your computer and use it in GitHub Desktop.
Save thinkphp/066d6c4b49effee007196fee56b50ebf to your computer and use it in GitHub Desktop.
AudioFileFactory.java
public class AudioFileFactory {
/**
creeaza o instanta AudioFile corespunzatoare in functie de extensia fisierului
@param path Calea catre fisierul audio
@return o instanta AudioFile corespunzatoare
@throws RuntimeException daca extensia fisierului nu este suportata
*/
public static AudioFile createAudioFile(String path) {
if(path == null || parth.isEmpty()) {
throw new RuntimeException("Path cannot be null or empty");
}
String lowercasePath = path.toLowerCase();
if(lowercasePath.endsWith(".wav")) {
return new WavFile( path );
} else if(lowercasePath.endsWith(".mp3") || lowercasePath.endsWith(".ogg")) {
return new TaggedFile( path );
} else {
throw new RuntimeException("Unknown suffix for AudioFile: " + path );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment