{"id":288,"date":"2019-08-16T17:22:37","date_gmt":"2019-08-16T09:22:37","guid":{"rendered":"http:\/\/www.mustenaka.cn\/?p=288"},"modified":"2019-08-16T17:31:53","modified_gmt":"2019-08-16T09:31:53","slug":"taglib001","status":"publish","type":"post","link":"https:\/\/www.mustenaka.cn\/index.php\/2019\/08\/16\/taglib001\/","title":{"rendered":"TagLib-Csharp(C#)\u5e38\u7528API\u4ee5\u53ca\u4e00\u4e9b\u89e3\u6790"},"content":{"rendered":"<p>TagLib\uff03\u7528\u4e8e\u5904\u7406\u5a92\u4f53\u6587\u4ef6\uff0c\u4f8b\u5982\u89c6\u9891\uff0c\u97f3\u9891\u548c\u7167\u7247\u7b49\u7b49\uff0cTagLib\uff03\u91c7\u7528LGPL\u548cMPL\u4e24\u79cd\u5f00\u6e90\u534f\u8bae\u3002TagLib#\u662f\u7528\u4e8e\u8bfb\u53d6\u548c\u7f16\u8f91\u51e0\u79cd\u6d41\u884c\u97f3\u9891\u683c\u5f0f\u7684\u5143\u6570\u636e\u7684\u5e93\u3002\u76ee\u524d\uff0c\u5b83\u652f\u6301 MP3\u6587\u4ef6\u7684ID3v1\u548cID3v2\uff0cFLAC\uff0cMPC\uff0cSpeex\uff0cWavPack\uff0cTrueAudio\uff0cWAV\uff0cAIFF\uff0cMP4\u548cASF\u6587\u4ef6\u4e2d\u7684Ogg Vorbis\u6ce8\u91ca\u548cID3\u6807\u7b7e\u548cVorbis\u6ce8\u91ca\u3002\u5176\u53ef\u4ee5\u7b80\u5316\u6211\u4eec\u5bf9mp3\u7b49\u5a92\u4f53\u6587\u4ef6\u7684\u5904\u7406\uff0c\u4e0d\u9700\u8981\u6211\u4eec\u6309\u7167\u5b57\u6bb5\u957f\u5ea6\u5206\u522b\u83b7\u53d6\u4fe1\u606f\uff0c\u800c\u662f\u76f4\u63a5\u8f93\u5165\u6240\u9700\u8981\u83b7\u53d6\u7684\u540d\u79f0\u83b7\u53d6\u3002<br \/>\n<!--more--><\/p>\n<p>C#\u7248\u672c\u7684\u5f00\u6e90\u5e93\u6765\u81ea\u4e8e<a href=\"https:\/\/github.com\/mono\/taglib-sharp\">https:\/\/github.com\/mono\/taglib-sharp<\/a>\uff0c\u4f46\u662f\u6211\u4eec\u4e00\u822c\u6dfb\u52a0\u7684\u65b9\u5f0f\u53ef\u4ee5\u76f4\u63a5\u5728vs\u4e2d\u7684\u83dc\u5355\u680f\u9009\u62e9\uff1a\u5de5\u5177&#8211;&gt;NuGet\u5305\u7ba1\u7406\u5668&#8211;&gt;\u7ba1\u7406\u89e3\u51b3\u65b9\u6848\u7684NuGet\u7a0b\u5e8f\u5305 \u8fdb\u5165&#8221;\u6d4f\u89c8&#8221;\u9875\u9762<\/p>\n<p>\u76f4\u63a5\u641c\u7d20TagLib\uff0c\u7b2c\u4e00\u4e2a\u5c31\u662f\uff0c\u76f4\u63a5\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2019\/08\/6UCF1CO4SYQF5D7IMR15V-300x123.png\" alt=\"\" width=\"916\" height=\"376\" class=\"alignnone wp-image-289\" srcset=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2019\/08\/6UCF1CO4SYQF5D7IMR15V-300x123.png 300w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2019\/08\/6UCF1CO4SYQF5D7IMR15V-768x315.png 768w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2019\/08\/6UCF1CO4SYQF5D7IMR15V-1024x420.png 1024w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2019\/08\/6UCF1CO4SYQF5D7IMR15V.png 1269w\" sizes=\"(max-width: 916px) 100vw, 916px\" \/><\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u505a\u4e00\u4e2a\u6d4b\u8bd5\u770b\u4e00\u4e0b\u662f\u5426\u6210\u529f\uff08\u5728\u539f\u6709\u7684\u7a0b\u5e8f\u8865\u5168\uff09\uff0c\u4f20\u9012\u7ed9\u51fd\u6570\u7684x\u4e3a\u6587\u4ef6\u5730\u5740\uff0c\u5176\u8981\u6c42\u4e3a\u7edd\u5bf9\u5730\u5740\uff0c\u5305\u542b\u6587\u4ef6\u540d\u4e0e\u683c\u5f0f\uff1a\u5982 C:\/\/test.mp3<\/p>\n<p>\u51fd\u6570\u4f1a\u5728\u63a7\u5236\u53f0\u8f93\u51fa\u97f3\u4e50\u6587\u4ef6\u7684\u6807\u9898\u4fe1\u606f\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" cs=\"\">using TagLib;\r\n\r\nprivate void GetMp3ImageFile(string x)\r\n{\r\n        TagLib.File xxxx = TagLib.File.Create(x);\r\n        string title = xxxx.Tag.Title;\r\n        Console.WriteLine(title);\r\n}<\/code><\/pre>\n<p>\u597d\u4e86\u5b8c\u6210\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\u3002<\/p>\n<p>\uff08<img decoding=\"async\" src=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2019\/08\/WRQ9_32ER3C@JGM5E5I-231x300.gif\" alt=\"\" width=\"231\" height=\"300\" class=\"alignnone size-medium wp-image-291\" \/>\uff09<\/p>\n<p>\u6b38\u6b38\u6b38\u522b\u6253\u6211\u561b\uff0c\u76ae\u8fd9\u4e00\u4e0b\u6211\u5f88\u5f00\u5fc3\u3002<\/p>\n<p>\u597d\u4e86\u8bf4\u56de\u6765\uff0cTabLib\u4e2d\u6700\u6838\u5fc3\u7684\u521b\u5efa\u6587\u4ef6\u4fe1\u606f\u7684\u8bed\u53e5\u662f<em>TagLib.File xxxx = TagLib.File.Create(new string(&#8220;xxxxx:\\\\xxxxx.mp3&#8221;));<\/em> \/\/\u53ef\u4ee5\u53bb\u6389new\uff0c\u76f4\u63a5\u5b58string<\/p>\n<p>\u8fd9\u53e5\u8bdd\u4e3a\u6587\u4ef6\u521b\u5efa\u51fa\u76f8\u5e94\u7684\u4fe1\u606f\uff0c\u5176\u6700\u4e3b\u8981\u7684\u5b89\u6392\u5728Tag\u548cProperties\u8def\u5f84\u4e0b\u8fd9\u91cc\u6311\u9009\u51e0\u4e2a\u5e38\u7528\u7684\u5c5e\u6027\u6807\u7b7e\uff1a<\/p>\n<blockquote><p><strong>TagLib.File:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>IsEmpty: \u5224\u65ad\u4fe1\u606f\u662f\u5426\u4e3a\u7a7a<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Tag\uff1a\u6807\u7b7e<\/strong><br \/>\nTag.Title: \u6807\u9898<br \/>\nTag.Album: \u4e13\u8f91<br \/>\nTag.Artists: \u6b4c\u624b<br \/>\nTag.Genres[]: \u7c7b\u578b<\/p>\n<p><strong>Properties\u5c5e\u6027<\/strong><br \/>\nProperties.AudioBitrate\uff1a\u97f3\u9891\u6bd4\u7279\u7387<br \/>\nProperties.AudioChannels\uff1a\u97f3\u9891\u9891\u9053<br \/>\nProperties.AudioSampleRate\uff1a\u97f3\u9891\u91c7\u6837\u7387<br \/>\nProperties.Description\uff1a\u63cf\u8ff0\uff0c\u5982&#8221;MPEG Version 1Audio,Layer 3&#8243;<br \/>\nProperties.Duration\uff1a\u64ad\u653e\u65f6\u957f<\/p><\/blockquote>\n<p>\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u672c\u4eba\u81ea\u5df1\u505a\u7684\u9879\u76ee\u4e2d\u7684\u4e00\u90e8\u5206\u4ee3\u7801\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" cs=\"\">       \/* \r\n         \u83b7\u53d6MP3\u6587\u4ef6\u4fe1\u606f\r\n         *\/\r\n\r\n         \/\/\u83b7\u53d6MP3\u4fe1\u606f--\u5305\u62ec\u56fe\u7247\u4fe1\u606f\r\n        private void GetMp3ImageFile(string x)\r\n        {\r\n            var y = x.Length;\r\n            \/\/\u5c06\u5f97\u5230\u7684\u6587\u4ef6\u5b9e\u4f8b\u5316\uff0cx\u4e3aMP3\u8def\u5f84       \r\n            TagLib.File xxxx = TagLib.File.Create(x);\r\n\r\n            \/\/\u6b4c\u66f2\u5c5e\u6027\u5747\u5728\u5b9e\u4f8b\u6587\u4ef6\u7684tag\u5c5e\u6027\u5c5e\u6027\u4e2d\r\n            string artist = xxxx.Tag.FirstArtist;\r\n            string title = xxxx.Tag.Title;\r\n            string album = xxxx.Tag.Album;\r\n            string[] performers = xxxx.Tag.Performers;\r\n\r\n            try {\r\n                MessageBox.Show(\"\u827a\u672f\u5bb6:\" + artist + \"\\n\" + \"\u6807\u9898:\" + title + \"\\n\" + \"\u5531\u7247\u96c6 \" + album + \"\\n\" + \"\u53c2\u4e0e\u521b\u4f5c\u7684\u827a\u672f\u5bb6 \" + performers[0]);\r\n            }\r\n            catch {\r\n\r\n            }\r\n            \r\n\r\n            \/\/\u4e0d\u4e00\u5b9a\u6bcf\u9996\u6b4c\u90fd\u6709\u4e13\u8f91\u56fe\u7247\uff0c\u9700\u8981\u5224\u65ad\r\n            if (xxxx.Tag.Pictures.Length &gt;= 1)\r\n            {\r\n                \/\/tag\u4e2d\u7684\u56fe\u7247\u4fe1\u606f\u4e3abyte\u6570\u7ec4\uff0c\u9700\u8981\u7528\u51fd\u6570\u8fdb\u884c\u8f6c\u5316\r\n                byte[] bin = xxxx.Tag.Pictures[0].Data.Data;\r\n                pictureBox1.Image = ReturnPhoto(bin);\/\/\u8f6c\u5316\u51fd\u6570\r\n            }\r\n            else\r\n            {\r\n                \/\/\u6ca1\u6709\u5c01\u9762\u5219\u663e\u793a\u5c01\u9762\u56fe\u7247\u7f3a\u5931\r\n                \/\/\u8fdb\u884c\u76f8\u5bf9\u8def\u5f84\u7684\u5904\u7406\r\n                string LakeImage = Application.StartupPath;\r\n                LakeImage = LakeImage.Substring(0, LakeImage.LastIndexOf(\"\\\\\"));\r\n                LakeImage = LakeImage.Substring(0, LakeImage.LastIndexOf(\"\\\\\"));\r\n                LakeImage += \"\\\\img\\\\lakepic.jpg\";\r\n\r\n                Console.WriteLine(LakeImage);\r\n                pictureBox1.Image = Image.FromFile(LakeImage);\r\n            }\r\n\r\n            \/\/string image = xxxx.Tag.Pictures[0].;\r\n        }\r\n\r\n\r\n        \/\/\u56fe\u7247\u4f20\u56de\r\n        public System.Drawing.Image ReturnPhoto(byte[] streamByte)\r\n        {\r\n            System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);\r\n            System.Drawing.Image img = System.Drawing.Image.FromStream(ms);\r\n            return img;\r\n        }\r\n<\/code><\/pre>\n<p>pictureBox1\u5c31\u662fForm\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u6700\u57fa\u672c\u7684\u56fe\u7247\u76d2\u7684\u6807\u51c6\u5185\u5bb9\uff0c\u76f4\u63a5\u8f93\u5165\u5373\u53ef\u3002<\/p>\n<p>\u6709\u90e8\u5206\u4fe1\u606f\u4f7f\u7528string\u6570\u7ec4\uff0c\u4f46\u662f\u8fd9\u4e9bstring\u6570\u7ec4\u57fa\u672c\u4fe1\u606f\u90fd\u53ea\u4fdd\u5b58\u5728\u9996\u4f4d\u5373string[0]\u8fd9\u91cc\uff0c\u6781\u5c11\u6709\u591a\u91cd\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TagLib\uff03\u7528\u4e8e\u5904\u7406\u5a92\u4f53\u6587\u4ef6\uff0c\u4f8b\u5982\u89c6\u9891\uff0c\u97f3\u9891\u548c\u7167\u7247\u7b49\u7b49\uff0cTagLib\uff03\u91c7\u7528LGPL\u548cMPL\u4e24\u79cd\u5f00\u6e90 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[33,48,49],"class_list":["post-288","post","type-post","status-publish","format-standard","hentry","category-csharp","tag-c","tag-csharp","tag-taglib"],"views":3415,"_links":{"self":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/comments?post=288"}],"version-history":[{"count":4,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":293,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/288\/revisions\/293"}],"wp:attachment":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/media?parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/categories?post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/tags?post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}