Created
April 17, 2025 17:23
-
-
Save thinkphp/066d6c4b49effee007196fee56b50ebf to your computer and use it in GitHub Desktop.
AudioFileFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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