日期:2014-05-18  浏览次数:20449 次

如何获取Internet上wma/mp3的歌曲信息?
Media   Player能够获取到这些信息,我想应该微软应该提供了这样的接口。

有这方面经验的朋友嘛?

我需要实现输入任意的wma及mp3地址,能够获取到文件的歌曲信息。

------解决方案--------------------
看到别人写的一个小东西,顺手用C#实现了。纯属娱乐。
using System;
using System.IO;
using System.Text;

namespace ShowMP3Tags
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
if(args.Length == 0)
{
Console.WriteLine(”Usage: ShowMP3Tags filename\n”);
return;
}

if(!File.Exists(args[0].Trim()))
{
Console.WriteLine(”File not found!\n”);
return;
}

using(FileStream fs = File.OpenRead(args[0].Trim()))
{
ID3Tag tag = new ID3Tag();

fs.Seek(-128, SeekOrigin.End);
fs.Read(tag.TAGID, 0, tag.TAGID.Length);
fs.Read(tag.Title, 0, tag.Title.Length);
fs.Read(tag.Artist, 0, tag.Artist.Length);
fs.Read(tag.Album, 0, tag.Album.Length);
fs.Read(tag.Year, 0, tag.Year.Length);
fs.Read(tag.Comment, 0, tag.Comment.Length);
fs.Read(tag.Genre, 0, tag.Genre.Length);

Console.WriteLine(Encoding.Default.GetString(tag.Title));
Console.WriteLine(Encoding.Default.GetString(tag.Artist));
Console.WriteLine(Encoding.Default.GetString(tag.Album));
Console.WriteLine(Encoding.Default.GetString(tag.Year));
Console.WriteLine(Encoding.Default.GetString(tag.Comment));
Console.WriteLine(Encoding.Default.GetString(tag.Genre));

Console.ReadLine();
}
}
}

class ID3Tag
{
public byte [] TAGID = new byte[3]; // 3, 必须是TAG
public byte [] Title = new byte[30]; // 30, 歌曲的标题
public byte [] Artist = new byte[30]; // 30, 歌曲的艺术家
public byte [] Album = new byte[30]; // 30, 专辑名称
public byte [] Year = new byte[4]; // 4, 出版年代
public byte [] Comment = new byte[30]; // 30, 评论
public byte [] Genre = new byte[1]; // 1, 种类标识
}
}
------解决方案--------------------
楼上这个取的应该是v1部分的信息,在mp3文件的后128byte
还有更多的扩展信息,在mp3文件的头部

具体的lz还是google一下各种音频文件的格式定义吧
实现思路基本就是用先下载文件,再逐字节的读入/转换对应信息

考虑到文件信息只占了整个文件的很小一部分,以上可以通过设置
HttpWebRequest.AddRange(),只取需要部分的Stream,
然后直接从Response的Stream中直接Read
------解决方案--------------------
mark