欢迎光临
我们一直在努力

利用C#显示MP3的标签信息-.NET教程,C#语言

建站超值云服务器,限时71元/月

//目的:列出mp3的一些标签信息

//作者:李艳庆

using system;

using system.io;

namespace mp3infons

{

class mp3info

{

struct mp3infostruct

{

public string mp3flag;

public string title;

public string singer;

public string album;

public string year;

public string comment;

}

private string mp3file;

mp3infostruct mp3struct;

public mp3info(string mp3name)

{

mp3file = mp3name;

mp3struct = new mp3infostruct();

}

public bool readmp3info()

{

bool isset=false;

byte[] b = new byte[128];

try

{

filestream fs = new filestream(mp3file, filemode.open);

fs.seek(-128, seekorigin.end);

fs.read(b, 0, 128);

mp3struct.mp3flag = system.text.encoding.default.getstring(b, 0, 3);

if (mp3struct.mp3flag.compareto("tag")==0)

{

//检查是否设置了标签

isset=true;

mp3struct.title = system.text.encoding.default.getstring (b,3,30);

mp3struct.singer = system.text.encoding.default.getstring (b,33,30);

mp3struct.album = system.text.encoding.default.getstring (b,63,30);

mp3struct.year = system.text.encoding.default.getstring (b,93,4);

mp3struct.comment = system.text.encoding.default.getstring (b,97,30);

}

fs.close();

}

catch(exception e)

{

system.console.writeline(e.message);

}

return isset;

}

public void printmp3info()

{

system.console.writeline("mp3附加信息:");

system.console.writeline("—————————–");

system.console.writeline("标 题: " + mp3struct.title);

system.console.writeline("歌 手: " + mp3struct.singer);

system.console.writeline("唱片集: " + mp3struct.album);

system.console.writeline("出版期: " + mp3struct.year);

system.console.writeline("备 注: " + mp3struct.comment);

}

}

public class mainmp3

{

static void main(string[] args)

{

if (args.length == 1)

{

mp3info mp3 = new mp3info(args[0]);

bool f = mp3.readmp3info();

if (f)

{

mp3.printmp3info();

}

else

{

system.console.writeline("该mp3没有标注");

}

}

else

{

system.console.writeline("参数不正确,只能跟一个参数");

}

}

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用C#显示MP3的标签信息-.NET教程,C#语言
分享到: 更多 (0)

相关推荐

  • 暂无文章