Extract song information from MP3

Source: Internet
Author: User
Tags file upload reserved
Extract song information from MP3
In addition to music information, a MP3 song contains information such as song name, singer and so on, when we listen to music with Winamp software, the playlist automatically reads the information. Most people like downloading music from the Internet, but download the MP3 file name is the file upload system automatically named, and the song itself simply does not match, so, to the user brought a lot of trouble. However, lazy people have the practice of lazy people, why don't we write a program, the song information automatically read out and automatically renamed for MP3 files?
Below I will use C # as a tool to write out the development process.
The extra information for a MP3 is held at the end of the file, representing a total of 128 bytes, including the following (we define a structure description):
public struct Mp3info
{
public string Identify;//tag, three bytes
public string title;//song name, 30 bytes
public string artist;//singer name, 30 bytes
public string album;//belongs to record, 30 bytes
public string year;//year, 4 characters
public string comment;//Comment, 28 bytes
Public char reserved1;//reserved bit, one byte
Public char reserved2;//reserved bit, one byte
Public char reserved3;//reserved bit, one byte
}
So, we can just read the last 128 bytes of the MP3 file and save it in the structure. The function is defined as follows:
<summary>
Get the last 128 bytes of the MP3 file
</summary>
<param name= "filename" > FileName </param>
<returns> return 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;
}
The byte array returned above is then segmented and saved into the MP3INFO structure for return.

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.