开发者

How can i find roughly time of song from its size

I have a song say about 5.1 mb ,i want to calculate total duration of song开发者_Go百科 before being played on media player the file format is wave file.


You need to decode the song in order to know the length of it:

    URL url = new URL("foo.wav");
    Clip clip = AudioSystem.getClip();
    AudioInputStream ais = AudioSystem.getAudioInputStream(url);
    clip.open(ais);
    System.out.println(clip.getMicrosecondLength());


It isn't really possible based on size. For example, an average MP3 is roughly 1 meg per minute, but if it has been encoded at the full 320 bit rate it can be a lot bigger than that. Your best bet would be to tell your script the size AND duration of the music file.


you can try this page : http://www.sounddevices.com/calculator/

for an uncompressed wav - 16 bit, 44.1kHz, stereo, you're looking at 172.2 KB/second, so around 10.332 MB/second. so your file is approx 0.5 minutes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜