using System;
using System.IO;
public class MP3Reader
{
public static void Main()
{
const int SIZE = 128;
byte[] data;
Console.Write("Enter name: ");
string name = Console.ReadLine();
if (!File.Exists(name))
{
Console.WriteLine("Not exists");
return;
}
try
{
FileStream file = File.OpenRead(name);
data = new byte[SIZE];
file.Seek(-128, SeekOrigin.End);
file.Read(data, 0, SIZE);
file.Close();
byte b1 = data[0];
byte b2 = data[1];
byte b3 = data[2];
if (Convert.ToChar(b1) != 'T' || Convert.ToChar(b2) != 'A' ||
Convert.ToChar(b3) != 'G')
{
Console.WriteLine("not mp3 valid");
return;
}
int i = 3;
string title = "";
for (; i < 33; i++)
{
if (data[i] != 0)
title += Convert.ToChar(data[i]);
}
string author = "";
for (i = 33; i < 63; i++)
{
if (data[i] != 0)
author += Convert.ToChar(data[i]);
}
string album = "";
for (i = 63; i < 93; i++)
{
if (data[i] != 0)
album += Convert.ToChar(data[i]);
}
string year = "";
for (i = 93; i < 97; i++)
{
if (data[i] != 0)
year += Convert.ToChar(data[i]);
}
string comments = "";
for (i = 97; i < 127; i++)
{
if (data[i] != 0)
comments += Convert.ToChar(data[i]);
}
Console.WriteLine("Data of MP3:");
Console.WriteLine("----------------------------");
Console.WriteLine();
Console.WriteLine("Title: " + title);
Console.WriteLine("Author: " + author);
Console.WriteLine("Album: " + album);
Console.WriteLine("Year: " + year);
Console.WriteLine("Comments: " + comments);
Console.WriteLine("Genre: " + data[127]);
}
catch (Exception)
{
Console.WriteLine("Error");
}
}
}