estou fazendo um player de música em java só pra aprender a mexer com o audio no mesmo, preciso pegar o tempo total da música para colocar na tabela onde ficam as músicas que o usuario inseriu, tipo o winamp (1. Nome_da_musica 5:24), queria saber como pegar o tempo total dela, o maximo que consegui foi pegar o tempo de execução com o getMicrosecondPosition() do SourceDataLine. Alguém tem alguma ideia?
@edit
dps de algumas horas pesquisando, eu achei uma solução, por incrivel q pareça é simples kkk. usando os links abaixo
http://docs.oracle.com/javase/1.5.0/docs/api/javax/sound/sampled/AudioFileFormat.html
http://docs.oracle.com/javase/tutorial/sound/converters.html
consegui fazer isso:
[code]static AudioFileFormat affFile;
public static long pegaDuracao(File f){
try {
affFile = AudioSystem.getAudioFileFormat(f);
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(affFile.properties());
return (Long) affFile.properties().get("duration");
}
public static String pegaNome(File f){
try {
affFile = AudioSystem.getAudioFileFormat(f);
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if((affFile.properties().get("author").equals("")) || (affFile.properties().get("author").equals("") && affFile.properties().get("title").equals("")))
return (String) affFile.properties().get("title");
else if(affFile.properties().get("title").equals(""))
return (String) affFile.properties().get("author")+" - "+f.getName();
else
return (String) affFile.properties().get("author")+" - "+affFile.properties().get("title");
}[/code]