Extract song information from MP3

Source: Internet
Author: User

Extract song information from MP3
In addition to music information, an MP3 song also contains information such as the song name and singer. When we use the winamp software to listen to music, the playlist will automatically read the information. Most people like to download music from the Internet, but the names of the downloaded MP3 files are automatically named by the file upload system, which is not consistent with the songs themselves, it brings a lot of trouble to users. However, if a lazy person is a lazy person, why don't we write a program that automatically reads the song information and renames the MP3 file?
Next I will write the development process using C # as a tool.
The additional information of an MP3 file is stored at the end of the file, which occupies 128 bytes, including the following content (we define a structure description ):
Public struct Mp3Info
{
Public string identify; // TAG, three bytes
Public string Title; // song name, 30 bytes
Public string Artist; // Artist name, 30 bytes
Public string Album; // The Album name, 30 bytes.
Public string Year; // Year, 4 characters long
Public string Comment; // Comment, 28 bytes
Public char reserved1; // Reserved Bit, one byte
Public char reserved2; // Reserved Bit, one byte
Public char reserved3; // reserved byte
}
Therefore, we only need to read the last 128 bytes of the MP3 file and save it to this structure. The function is defined as follows:
/// <Summary>
/// Obtain the last 128 bytes of the MP3 file
/// </Summary>
/// <Param name = "FileName"> file name </param>
/// <Returns> returns a byte array </returns>
Private byte [] getLast128 (string FileName)
{
FileStream fs = new FileStream (FileName, FileMode. Open, FileAccess. Read );
Stream stream = fs;
Stream. Seek (-128, SeekOrigin. End );
Const int seekPos = 128;
Int rl = 0;
Byte [] Info = new byte [seekPos];
Rl = stream. Read (Info, 0, seekPos );
Fs. Close ();
Stream. Close ();
Return Info;
}
Segment the byte array returned above and save it to the Mp3Info structure.

Related Article

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.