Always want to do network music player, but they do not have a server, simply can not be achieved, nor that ability to achieve. The only way to do that is by using someone else's API.
There are very few APIs published online, like the real address of a music file that can be directly obtained, and some of it just captures traffic. Big companies that want to make music can share some APIs through an open platform.
Method one. http://box.zhangmen.baidu.com/x?op=12&count=1&title=song$$
This address is the most commonly used, the song will be changed to the name of the songs you can get the address information set, the return is an XML file, the address should be resolved to use
<url><encode><! [cdata[http://zhangmenshiting.baidu.com/data2/music/29969688/ Y2tsam5sb3bfn6nndk6ap5wxcjexm2hok2tlmwqcbgxlk5eabppncjdjlmexm5uezpvpzgvpbgmwlwmybjppbwpma1qin5t1ywbmbw1ra2tkawdlamlnbte $]]></encode><decode><! [cdata[29969688.mp3?xcode=cbe10b92e5f544adf9d08f1c3bedf5c600351ec6d7d25948&mid=0.39854337415305]]></ Decode><type>8</type><lrcid>0</lrcid><flag>0</flag></url>
Parsing method: XmlDocument class, the following is the key code, the URL is the real address
XmlDocument XML = new XmlDocument (); Xml. LOADXML (info);//info is the XML content foreach (XmlElement item in XML. Documentelement.childnodes) {if (item. InnerText = = "0") return null; String Deurl, Enurl, LRC; if (item. Name = = "url") {Deurl = Item. selectSingleNode ("encode"). InnerText; Enurl = Item. selectSingleNode ("Decode"). InnerText; LRC = Item. selectSingleNode ("Lrcid"). InnerText; if (LRC = = "0") {LRC = "no lyrics"; } else {LRC = Strlrcpath + (Int32.Parse (LRC)/100). ToString () + "/" + LRC + ". LRC"; } int id = Deurl. LastIndexOf ('/'); String Url=deurl. Substring (0, ID + 1) + Enurl; } }
Method Two. http://sug.music.baidu.com/info/suggestion?format=json&version=2&from=0&word=song&_= 1405404358299
Change song to title, get the basic information set (song ID, name, singing)
{"Data": {"song": [{"SongID": "293547", "Songname": "\u4e0d\u5f97\u4e0d\u7231", "Artistname": "\u6f58\u73ae\u67cf,\ U5f26\u5b50 "},{" SongID ":" 7315028 "," Songname ":" \u4e0d\u5f97\u4e0d\u7231 "," Artistname ":" \u5f26\u5b50,\u6f58\ U73AE\U67CF "},{" SongID ":" 2119510 "," Songname ":" \u4e0d\u5f97\u4e0d\u7231 "," Artistname ":" \u5f26\u5b50 "},{" SongID " : "7332815", "Songname": "\u4e0d\u5f97\u4e0d\u7231", "Artistname": "\u60c5\u6b4c\u4f34\u4fa3"},{"SongID": "274710", " Songname ":" \u4e0d\u5f97\u4e0d\u7231 "," Artistname ":" \u5f6d\u4f73\u6167 "},{" SongID ":" 1204608 "," Songname ":" \u4e0d \u5f97\u4e0d\u7231 "," Artistname ":" \u502a\u96c5\u4e30 "},{" SongID ":" 59942403 "," Songname ":" \u4e0d\u5f97\u4e0d\ u7231 "," Artistname ":" \u7fa4\u661f "},{" SongID ":" 84940143 "," Songname ":" \u4e0d\u5f97\u4e0d\u7231 "," artistname ":" \ U8bb8\u5d69,britney Spears "},{" SongID ":" 1288459 "," Songname ":" \U4E0D\U5F97\U4E0D\U7231_\U6F58\U73AE\U67CF "," Artistname ":" \u821e\u66f2\u5927\u9605\u5175 "},{" SongID ":" 64773595 "," Songname ":" \u4e0d\u5f97\u4e0d\u7231dj-\ u6f58\u73ae\u67cfvs\u5f26\u5b50 mcyy Mix "," Artistname ":" Mcyy "}]," Artist ": []," album ": [{" albumID ":" 83672939 "," Albumname ":" \u4e0d\u5f97\ u4e0d\u7231 "," Artistname ":" \u6587\u6587\u4e50\u9053 "," Artistpic ":" http:\/\/a.hiphotos.baidu.com\/ting\/pic\/ Item\/f3d3572c11dfa9ec81637f0c60d0f703918fc15f.jpg "}]}," Pro ": [" Song "," album "]}
Analytic method: Using Newtonsoft.json
After getting the song ID, using Http://ting.baidu.com/data/music/links?songIds=mid&format=json, change mid to the song ID to query the details, Songlink is the real address of the song.
{"ErrorCode": 22000, "data": {"Xcode": "C91c710aab6c9acd577895e58b3b93ef", "songList": [{"Queryid": "293547", "SongID" : 293547, "Songname": "\u4e0d\u5f97\u4e0d\u7231", "ArtistID": "6113,1427", "Artistname": "\u6f58\u73ae\u67cf,\u5f26\ U5b50 "," albumID ": 2452656," Albumname ":" Will\u0027s \u672a\u6765\u5f0f "," Songpicsmall ":" http:\/\/ c.hiphotos.baidu.com\/ting\/pic\/item\/http:\/\/qukufile2.qianqian.com\/data2\/pic\/115458867\/115458867. Jpg.jpg "," Songpicbig ":" Http:\/\/c.hiphotos.baidu.com\/ting\/pic\/item\/http:\/\/qukufile2.qianqian.com\/data2\ /pic\/115458852\/115458852.jpg.jpg "," Songpicradio ":" http:\/\/c.hiphotos.baidu.com\/ting\/pic\/item\/http:\/\/ Qukufile2.qianqian.com\/data2\/pic\/115458827\/115458827.jpg.jpg "," Lrclink ":" \/data2\/lrc\/13802189\/13802189. LRC "," Version ":", "Copytype": 1, "Time": 279, "Linkcode": 22000, "Songlink": "http:\/\/zhangmenshiting.baidu.com\/ Data2\/music\/42825245\/2935471405447261.mp3?xcode=c91c710aab6c9acd795318c09ac1e37e069471290618b128 "," ShowLink ":" Http:\/\/zhangmenshiting.baidu.cOm\/data2\/music\/42825245\/2935471405447261.mp3?xcode=c91c710aab6c9acd795318c09ac1e37e069471290618b128 "," Format ":" MP3 "," rate ": +," size ": 4471745," relatestatus ":" 0 "," resourcetype ":" 0 "}]}}
Method three (test invalid):
Http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&ie=utf-8&word=song&format=json
This address can be used before, but the content returned is always empty
Http://play.baidu.com/data/music/songinfo
This address needs to be submitted as post and data is Songids=mid (mid is the song ID)
Http://play.baidu.com/data/music/songlink
This address needs to be submitted by post, data is songids=mid&hq=1&type=m4a%2cmp3&rate=&pt=0&flag=-1&s2p=-1& Prerate=-1&bwt=-1&dur=-1&bat=-1&bp=-1&pos=-1&auto=-1 (mid is the song ID)
For the use of the music API, please refer to this article, because these APIs are not published, so it may expire one day, I will update this API at any time
Please do not reprint