c# 通过解析mp3规范命名并上传服务器

引用
using Shell32;
        private void Open_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "MP3 Files(.mp3)|*.mp3|WMA Files(*.wma)|*.WMA";
//ofd.Multiselect = true; //允许多选
ofd.RestoreDirectory = true; //记住上一次的文件路径
ofd.ShowDialog();
FilePath = ofd.FileName;
if (FilePath != "")
{
string OpenFileType = Path.GetExtension(FilePath);
FileInfo FileLenght = new FileInfo(FilePath);
if (FileLenght.Length > )
{
FuncClass.ShowError("Too Large!");
}
else
{
ShellClass sh = new ShellClass();
Folder dir = sh.NameSpace(Path.GetDirectoryName(FilePath));
FolderItem item = dir.ParseName(Path.GetFileName(FilePath));
string NewPath = Path.GetDirectoryName(FilePath) + "\\" + dir.GetDetailsOf(item, ) + " - " +
dir.GetDetailsOf(item, ) + OpenFileType;
if (!File.Exists(NewPath))
{
File.Move(FilePath, NewPath);//重命名其实就是move
}
dir = sh.NameSpace(Path.GetDirectoryName(NewPath));
item = dir.ParseName(Path.GetFileName(NewPath));
PathFile.Text = NewPath;
FileName.Text = Path.GetFileNameWithoutExtension(NewPath) + OpenFileType;
MusicName.Text = dir.GetDetailsOf(item, );
WriteWords.Text = "";
WriteMusic.Text = "";
Singer.Text = dir.GetDetailsOf(item, );
Album.Text = dir.GetDetailsOf(item, );
Time.Text = dir.GetDetailsOf(item, );
}
}
}

解析说明:例子周杰伦 - 青花瓷.mp3

-1 项目类型:MP3文件
大小:3.62
参与创作的艺术家:周杰伦
长度:00:03:57
0:青花瓷.mp3(文件名)
1: 3.62MB(大小)
2: MP3文件(项目类型)
3:xxxx-xx-xx xx:xx(修改时间)
9: 音频(文件类型)
10:Administrators(用户名)
11:音乐(所属)
13:周杰伦(演唱)
14:一人一首成名曲(专辑)
15: 2002(年份)
19:未分级
20:周杰伦(演唱)
21:青花瓷(歌名)
27: 00:03:57
28:128kbps
29:否

修改后周杰伦 - 青花瓷.mp3

图例:

c# 通过解析mp3规范命名并上传服务器

打开后显示已修正得到歌曲信息:

c# 通过解析mp3规范命名并上传服务器

        private void UpLoad()
{  //wenserver需自己定义
WebClient webclient = new WebClient();
byte[] responseArray = webclient.UploadFile("http://192.168.1.11/WebForm1.aspx ", "POST", @"" + FilePath + "");//http路径
string getPath = Encoding.GetEncoding("UTF-8").GetString(responseArray);
FuncClass.ShowInformation("歌曲已"+getPath + "上传到服务器");//返回信息
}
上一篇:「雕爷学编程」Arduino动手做(39)——DS18B20温度传感器


下一篇:leecode第二百三十一题(2的幂)