Java programming method for obtaining mp3 duration and playing mp3 files, javamp3

Source: Internet
Author: User

Java programming method for obtaining mp3 duration and playing mp3 files, javamp3

This article describes how to obtain mp3 duration and play mp3 files by Java programming. We will share this with you for your reference. The details are as follows:

The required packages are jaudiotagger-2.2.6-SNAPSHOT.jar and jl1.0.1.jar.

Import java. io. bufferedInputStream; import java. io. file; import java. io. fileInputStream; import org. jaudiotagger. audio. audioFileIO; import org.jaudiotagger.audio.pdf. MP3AudioHeader; import org.jaudiotagger.audio.pdf. MP3File; import javazoom. jl. player. player; public class MusicUtil {public static void play (String position) {try {BufferedInputStream buffer = new BufferedInputStream (new FileInputStream (position); Player player = new Player (buffer ); player. play ();} catch (Exception e) {e. printStackTrace () ;}} public static int getDuration (String position) {int length = 0; try {MP3File mp3File = (MP3File) AudioFileIO. read (new File (position); MP3AudioHeader audioHeader = (MP3AudioHeader) mp3File. getAudioHeader (); // The unit is second length = audioHeader. getTrackLength (); return length;} catch (Exception e) {e. printStackTrace ();} return length;} public static void main (String [] args) {String position = "escape plan-the brightest star node in the night sky"; getDuration (position); play (position );}}

For more java-related content, refer to this topic: java image operation skills summary, java Date and Time Operation Skills summary, Java operation DOM node skills summary, Java file and directory operation skills summary, and Java data structure and algorithm tutorial.

I hope this article will help you with java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.