Get the App
SLTechnology News&Howtos  ›  Development  › 

How to obtain MP3 Audio duration by Java

Shulou Source: shulou.com Published: 2022-06-02 22:45:35 10月25日 Update

This article mainly introduces how to achieve Java to obtain MP3 audio duration, the article is very detailed, has a certain reference value, interested friends must read it!

Maven relies on org jaudiotagger 2.0.1 code import org.jaudiotagger.audio.AudioFileIO;import org.jaudiotagger.audio.mp3.MP3AudioHeader;import org.jaudiotagger.audio.mp3.MP3File;import java.io.File / * * @ Author huyi @ Date 15:06 @ Description on 2021-9-30: mp3 audio tool * / public class AudioMp3Utils {/ * obtain the playback duration of mp3 voice files (seconds) mp3 * * @ param filePath * @ return * / public static void getMp3Duration (String filePath) {try {File mp3File = new File (filePath); MP3File f = (MP3File) AudioFileIO.read (mp3File); MP3AudioHeader audioHeader = (MP3AudioHeader) f.getAudioHeader () System.out.println ("duration:" + Float.parseFloat (audioHeader.getTrackLength () + "));} catch (Exception e) {e.printStackTrace ();}} public static void main (String [] args) {getMp3Duration (" E:\ csdn\\ dzgz.mp3 ");}}

Execution result:

The above is all the content of the article "how to obtain MP3 Audio duration by Java". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Duration audio content articles code value interests guys buddies tools documents more knowledge results industry voice information information channels audio tools channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MySQL Shulou Information Xiaomi Microsoft