java - How to get duration of audio file? -
i want duration (total time) of audio file in seconds. audio file can of format i.e. (.mp3, .wav, .wma etc.).
try { file file = new file("c:/users/administrator/appdata/local/temp/" + "01 - ab tere bin jee lenge hum-(mymp3singer.com).mp3"); audioinputstream audioinputstream = audiosystem.getaudioinputstream(file); audioformat format = audioinputstream.getformat(); long frames = audioinputstream.getframelength(); double durationinseconds = (frames + 0.0) / format.getframerate(); system.out.println("duration in seconds"+durationinseconds); audiofileformat audiofileformat = audiosystem.getaudiofileformat(file); map<string, object> properties = audiofileformat.properties(); system.out.println("properties"+properties.size()+"empy::"+properties.isempty()); for(string key: properties.keyset()){ system.out.println(key +" :: "+ properties.get(key).tostring()); } } catch (exception e) { system.out.println("exception:::::" + e.getmessage()); }
i have tried using above code giving:
exception:::::could not audio input stream input file
you missing mp3 codecs. might want try tritonus: open source java sound.
also check related thread: mp3 playback using java sound , sun mp3 plugin
Comments
Post a Comment