How to read the logo information of mp3 songs

Source: Internet
Author: User
This programming method mainly reads the name of the MP3 song file in bytes, the artist and the File marker information such as the release date, which is located at the end of the MP3 file and starts with "tag, it consists of 128 bytes. The main source code is as follows:
Namespace windowsapplication1
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}

Private void button#click (Object sender, eventargs E)
{// Determine whether the directory already exists
String mydir1 = @ "C:/Windows/system ";
String mydir2 = @ "C:/window/system ";
String myinfo = "";
If (directory. exists (mydir1 ))
Myinfo + = mydir1 + "the directory already exists! /N ";
Else
Myinfo + = mydir1 + "the directory does not exist! /N ";
If (directory. exists (mydir2 ))
Myinfo + = mydir2 + "the directory already exists! /N ";
Else
Myinfo + = mydir2 + "the directory does not exist! /N ";
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}

Private void button2_click (Object sender, eventargs E)
{// Determine whether the file already exists
String myfile1 = @ "C:/boot. ini ";
String myfile2 = @ "D:/boot. ini ";
String myinfo = "";
If (file. exists (myfile1 ))
Myinfo + = myfile1 + "the file already exists! /N ";
Else
Myinfo + = myfile1 + "the file does not exist! /N ";
If (file. exists (myfile2 ))
Myinfo + = myfile2 + "the file already exists! /N ";
Else
Myinfo + = myfile2 + "the file does not exist! /N ";
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}

Private void button3_click (Object sender, eventargs E)
{// Obtain the current working directory
String mypath = "the current working directory is :";
Mypath + = directory. getcurrentdirectory ();
MessageBox. Show (mypath, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}
Private void button4_click (Object sender, eventargs E)
{// Set the current working directory
String myinfo = "set the current working directory :";
String mypath = "C: // windows ";
Directory. setcurrentdirectory (mypath );
Myinfo + = mypath + "operation successful! ";
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}

Private void button5_click (Object sender, eventargs E)
{// Create and read temporary files
String mytempfile = path. gettempfilename ();
// Write information to the temporary file
Filestream mystream = new filestream (mytempfile, filemode. Open );
Streamwriter mywriter = new streamwriter (mystream, encoding. utf8 );
Mywriter. writeline (mytempfile + "the content of the temporary file is as follows :");
Foreach (string myfilename in directory. getfiles ("C ://"))
Mywriter. writeline (myfilename );
Mywriter. Flush ();
Mywriter. Close ();
Mystream. Close ();
// Read information from a temporary file
Streamreader myreader = new streamreader (mytempfile, encoding. utf8 );
String myinfo = myreader. readtoend ();
Myreader. Close ();
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
// Delete a temporary file
File. Delete (mytempfile );
}

Private void button6_click (Object sender, eventargs E)
{// Manage independent storage files
Isolatedstoragefile mystore = isolatedstoragefile. getuserstoreforassembly ();
// Create a folder in the independent storage
Mystore. createdirectory ("myfolder ");
// Create an independent storage file
Stream mystream = new isolatedstoragefilestream ("myfile3.txt", filemode. Create, mystore );
// Stream mystream = new isolatedstoragefilestream ("myfile2.txt", filemode. Create, mystore );
// Stream mystream = new isolatedstoragefilestream ("myfile3.txt", filemode. Create, mystore );
// Stream mystream = new isolatedstoragefilestream ("myfile4.txt", filemode. Create, mystore );
// Stream mystream = new isolatedstoragefilestream ("myfile5.txt", filemode. Create, mystore );
Streamwriter mywriter = new streamwriter (mystream, encoding. utf8 );
Mywriter. writeline ("C: // files in the folder include :");
Foreach (string myfilename in directory. getfiles ("C ://"))
Mywriter. writeline (myfilename );
Mywriter. Flush ();
Mywriter. Close ();
Mystream. Close ();
String myinfo = "";
// Information in the independent storage area
Myinfo + = "current size:" + mystore. currentsize. tostring () + "/N ";
Myinfo + = "Storage range:" + mystore. Scope. tostring () + "/N ";
Myinfo + = "included files:/N ";
String [] myfiles = mystore. getfilenames ("*.*");
Foreach (string myfile in myfiles)
{
Myinfo + = myfile + "/N ";
}
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}

Private void button7_click (Object sender, eventargs E)
{// Monitoring File Creation and deletion operations
// Configure the file system monitor
Filesystemwatcher mywatch = new filesystemwatcher ();
Mywatch. Path = application. startuppath;
Mywatch. Filter = "*.*";
Mywatch. includesubdirectories = true;
// Add the file system monitor event handle
Mywatch. Created + = new filesystemeventhandler (oncreatedordeleted );
Mywatch. Deleted + = new filesystemeventhandler (oncreatedordeleted );
Mywatch. enableraisingevents = true;
If (file. exists ("mytestfile.txt "))
{
File. Delete ("mytestfile.txt ");
}
Filestream mystream = new filestream ("mytestfile.txt", filemode. Create );
Mystream. Close ();
}
Private Static void oncreatedordeleted (Object sender, filesystemeventargs E)
{// A prompt message is displayed when the file is created and deleted in the current directory.
String myinfo = E. fullpath + "file succeeded ";
Switch (E. changetype)
{
Case watcherchangetypes. created:
Myinfo + = "create! ";
Break;
Case watcherchangetypes. Deleted:
Myinfo + = "Delete! ";
Break;
}
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}

Private void button8_click (Object sender, eventargs E)
{// Encrypt the account dependency file, and then try to open the file under another account
String myfile = "mytext.txt ";
File. Encrypt (myfile );
}
Private void button9_click (Object sender, eventargs E)
{// Decrypt the account dependent File
String myfile = "mytext.txt ";
File. decrypt (myfile );
}

Private void button10_click (Object sender, eventargs E)
{// Obtain the execution file path of the Startup Program
String myinfo = "the path to the executable file that started the application is:/N" + application. executablepath;
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}

Private void button11_click (Object sender, eventargs E)
{// Obtain the execution file directory of the Startup Program
String myinfo = "the directory of the executable file that started the application is:/N" + application. startuppath;
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}

Private void button12_click (Object sender, eventargs E)
{// Read the MP3 song file Flag Information
String myfilename = "C: // after.pdf ";
Filestream mystream = new filestream (myfilename, filemode. Open );
Mystream. Seek (-128, seekorigin. End );
Byte [] mytag = new byte [3];
Mystream. Read (mytag, 0, 3 );
String myinfo = myfilename + "The Song information is as follows :";
If (system. Text. encoding. Default. getstring (mytag) = "tag ")
{
Myinfo + = "/n song name:" + gettagdata (mystream, 30 );
Myinfo + = "/n ARTIST:" + gettagdata (mystream, 30 );
Myinfo + = "/n :" + gettagdata (mystream, 30 );
Myinfo + = "/N Release Date:" + gettagdata (mystream, 4 );
}
Mystream. Close ();
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}
Private string gettagdata (Stream mystream, int mylength)
{
Byte [] mybytes = new byte [mylength];
Mystream. Read (mybytes, 0, mylength );
String mytagdata = system. Text. encoding. Default. getstring (mybytes );
Char [] mytrimchars = {Char. parse ("")};
Mytagdata = mytagdata. Trim (mytrimchars );
Return mytagdata;
}

Private void button13_click (Object sender, eventargs E)
{// Specify the encoding method for saving the file
Filestream mystream = new filestream ("myutf8utf16ascii. bin", filemode. Create );
Streamwriter myutf8 = new streamwriter (mystream, encoding. utf8 );
Myutf8.write ("this is in utf8 ");
Myutf8.flush ();
Streamwriter myutf16 = new streamwriter (mystream, encoding. Unicode );
Myutf16.write ("this is in UTF16 ");
Myutf16.flush ();
Streamwriter myascii = new streamwriter (mystream, encoding. ASCII );
Myascii. Write ("this is in ASCII ");
Myascii. Flush ();
Myascii. Close ();
}

Private void button14_click (Object sender, eventargs E)
{// Read the wav song file Flag Information
String myfile = application. startuppath + "// Windows XP startup .wav ";
Fileinfo myfileinfo = new fileinfo (myfile );
System. Io. filestream mystream = myfileinfo. openread ();
String myinfo = myfile + "the file's flag information is as follows :";
If (mystream. length> = 44)
{
Byte [] mybytes = new byte [44];
Mystream. Read (mybytes, 0, 44 );
System. Text. encoding. Default. getstring (mybytes, 0, 4 );

If (system. text. encoding. default. getstring (mybytes, 0, 4) = "riff" & system. text. encoding. default. getstring (mybytes, 8, 4) = "wave" & system. text. encoding. default. getstring (mybytes, 12, 4) = "FMT ")
{
Myinfo + = "/n groupid:" + system. Text. encoding. Default. getstring (mybytes, 0, 4) as string;
System. bitconverter. toint32 (mybytes, 4 );
Myinfo + = "/n filesize:" + system. bitconverter. toint32 (mybytes, 4) as string;
Myinfo + = "/n rifftype:" + system. Text. encoding. Default. getstring (mybytes, 8, 4) as string;
Myinfo + = "/n chunkid:" + system. Text. encoding. Default. getstring (mybytes, 12, 4) as string;
Myinfo + = "/n chunksize:" + system. bitconverter. toint32 (mybytes, 16) as string;
Myinfo + = "/n wformattag:" + system. bitconverter. toint16 (mybytes, 20) as string;
Myinfo + = "/n wchannels:" + system. bitconverter. touint16 (mybytes, 22) as string;
Myinfo + = "/n dwsamplespersec:" + system. bitconverter. touint32 (mybytes, 24) as string;
Myinfo + = "/n dwavbytespersec:" + system. bitconverter. touint32 (mybytes, 28) as string;
Myinfo + = "/n wblockalign:" + system. bitconverter. touint16 (mybytes, 32) as string;
Myinfo + = "/n wbitspersample:" + system. bitconverter. touint16 (mybytes, 34) as string;
Myinfo + = "/n datachunkid:" + system. Text. encoding. Default. getstring (mybytes, 36, 4) as string;
Myinfo + = "/n datasize:" + system. bitconverter. toint32 (mybytes, 40) as string;
}
}
Mystream. Close ();
MessageBox. Show (myinfo, "message prompt", messageboxbuttons. OK, messageboxicon. information );
}
}
 

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.