c# 通過解析mp3規範命名並上傳伺服器

來源:互聯網
上載者:User

標籤:winform   style   blog   http   color   檔案   

引用
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 > 10240000)                {                    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, 20) + " - " +                                     dir.GetDetailsOf(item, 21) + 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, 21);                    WriteWords.Text = "";                    WriteMusic.Text = "";                    Singer.Text = dir.GetDetailsOf(item, 13);                    Album.Text = dir.GetDetailsOf(item, 14);                    Time.Text = dir.GetDetailsOf(item, 27);                }            }        }

解析說明:例子周杰倫 - 青花瓷.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

圖例:

開啟後顯示已修正得到歌曲資訊:

        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 + "上傳到伺服器");//返回資訊        }
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.