Here, I will show you how to get the time duration for an Audio File playing in a Java Desktop App. You should know the following things first:
- How to play an Audio File (.mp3)
You need to use
The Code:
private void playMe(){
try{
File file=new File("F:\\Net Beans Work Space\\mp3\\a.mp3");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
int duration=0;
AudioFile audioFile = AudioFileIO.read(file);
duration= audioFile.getAudioHeader().getTrackLength();
System.out.print("time in milliseconds= "+duration) ;
player.play();
}catch(Exception e){
System.out.print("ERROR "+e);
}
}