Read MP3 file header information (id3v1)

Source: Internet
Author: User

A relatively simple program does not have much to use. I just want to know if it will produce results.

Tired is very tired, but still feel very passionate!
It feels good to write a bit of information about reading the MP3 file ID3V1!
Recently, I used Swing to write a program for renaming MP3 files based on tag information. It seems that it is not very difficult to hear this, but many problems have been encountered in the actual process, all need to be solved one by one!
One of the major mistakes I made when searching for help was that I didn't save or link some good articles.
Otherwise, paste the program that reads the MP3 file header information first:

/**//**
* Created on 5:10:29
* @ Author: Confused ghost
*/
Public class ReadMp3ID3v1Info {
Private static final int tag size = 128;
Private static final int TITLE_SIZE = 30;
Private static final int ARTIST_SIZE = 30;
Private static final int ALBUM_SIZE = 30;
Private Static final int year_size = 4;
Private Static final int comment_size = 29;
Private Static final int track_location = 126;
Private Static finals int genre_location = 127;
Private Static final int max_genre = 255;
Private Static final int max_track = 255;
Private Static final string enc_type = "cp437 ";
Private Static final string tag_start = "tag ";

Public static void main (string [] ARGs ){
Try {
File MP3 = new file ("F:/music/MP3/English singer/Madonna-musicloud ");
Randomaccessfile RAF = new randomaccessfile (MP3, "R ");
Raf. Seek (RAF. Length ()-tag_size );
Byte [] Buf = new byte [tag_size];
Raf. Read (BUF, 0, tag_size );
String tag = new String (buf, 0, TAG_SIZE, "Cp437 ");
Int start = TAG_START.length ();
System. out. println ("file name:" + mp3.getName ());
System. out. println ("title:" + tag. substring (start, start + = TITLE_SIZE). trim ());
System. out. println ("Artist:" + tag. substring (start, start + = ARTIST_SIZE). trim ());
Raf. close ();

System. out. println ("======================================" );

File mp32 = new File ("F:/music/MP3/English combination/blue-you make me wanna.mp3 ");
Raf = new RandomAccessFile (mp32, "r ");
Raf. seek (raf. length ()-128 );
Raf. read (buf, 0,128 );
Tag = new String (buf, 0,128, "Cp437 ");
Start = TAG_START.length ();
System. out. println ("file name:" + mp32.getName ());
System. out. println ("title:" + tag. substring (start, start + = 30). trim ());
System. out. println ("Artist:" + tag. substring (start, start + = 30). trim ());
Raf. close ();
} Catch (Exception e ){
}
}
}

The running result is:
File Name: Madonna-musicloud
Title: Music
Artist: Madonna
==========================================
File Name: blue-you make me wanna.pdf
Title: U Make Me Wanna
Artist: Blue

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.