How do I get a sound file\'s total time in Java?
--UPDATE
Looks like this code does de work: long audioFileLength = audioFile.length();
r
This is a easy way:
FileInputStream fileInputStream = null;
long duration = 0;
try {
fileInputStream = new FileInputStream(pathToFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
duration = Objects.requireNonNull(fileInputStream).getChannel().size() / 128;
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(duration)