网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计资源 > .Net编程 > 正文

百度音乐搜索API在C#中的运用

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务
  1. using System; 
  2.  
  3. using System.Collections.Generic; 
  4.  
  5. using System.ComponentModel; 
  6.  
  7. using System.Data; 
  8.  
  9. using System.Drawing; 
  10.  
  11. using System.Text; 
  12.  
  13. using System.Xml; 
  14.  
  15. using System.Windows.Forms; 
  16.  
  17.  
  18.  
  19. namespace BaiDuAPI 
  20.  
  21.  
  22.     public partial class Form1 : Form 
  23.  
  24.     { 
  25.  
  26.         public Form1() 
  27.  
  28.         { 
  29.  
  30.             InitializeComponent(); 
  31.  
  32.  
  33.  
  34.             this.skinEngine1.SkinFile = "vista1_green.ssk"
  35.  
  36.         } 
  37.  
  38.  
  39.  
  40.         private void button1_Click(object sender, EventArgs e) 
  41.  
  42.         { 
  43.  
  44.             System.Media.SoundPlayer sp = new System.Media.SoundPlayer(); 
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.             try 
  53.  
  54.             { 
  55.  
  56.                 string strEncode = ""
  57.  
  58.  
  59.  
  60.                 string strDecode = ""
  61.  
  62.  
  63.  
  64.                 string strLrc = ""
  65.  
  66.  
  67.  
  68.                 string strExt = ""
  69.  
  70.  
  71.  
  72.                 string strPath = ""
  73.  
  74.  
  75.  
  76.                 string AppString; 
  77.  
  78.  
  79.  
  80.                 string AppAPI = GetMP3URL(textBox4.Text); 
  81.  
  82.  
  83.  
  84.                 if (AppAPI == "nothing"
  85.  
  86.                 { 
  87.  
  88.                     MessageBox.Show("找不到音乐 " + textBox4.Text + " 请更换查询名称"); 
  89.  
  90.  
  91.  
  92.                     return
  93.  
  94.                 } 
  95.  
  96.                 else 
  97.  
  98.                 { 
  99.  
  100.                     AppString = AppAPI.Split(" ".ToCharArray()); 
  101.  
  102.  
  103.  
  104.                     strEncode = AppString[0].ToString();            //编码 
  105.  
  106.  
  107.  
  108.                     strDecode = AppString.ToString();            //解码 
  109.  
  110.  
  111.  
  112.                     strExt = AppString.ToString();               //扩展名 
  113.  
  114.  
  115.  
  116.                     strLrc = AppString.ToString();               //歌词URL 
  117.  
  118.  
  119.  
  120.                     strPath = AppString.ToString();              //歌曲URL 
  121.  
  122.  
  123.  
  124.                     textBox1.Text = strEncode; 
  125.  
  126.  
  127.  
  128.                     textBox2.Text = strDecode; 
  129.  
  130.  
  131.  
  132.                     textBox3.Text = strPath; 
  133.  
  134.  
  135.  
  136.                     textBox5.Text = strExt; 
  137.  
  138.  
  139.  
  140.                     textBox6.Text = strLrc; 
  141.  
  142.                 } 
  143.  
  144.             } 
  145.  
  146.             catch 
  147.  
  148.             { 
  149.  
  150.                 MessageBox.Show("找不到音乐 " + textBox4.Text + " 请更换查询名称"); 
  151.  
  152.             } 
  153.  
  154.  
  155.  
  156.         } 
  157.  
  158.  
  159.  
  160.         public string GetMP3URL(string fString) 
  161.  
  162.         { 
  163.  
  164.             try 
  165.  
  166.             { 
  167.  
  168.                 string strAPI = "http://box.zhangmen.baidu.com/x?op=12&count=1&title="
  169.  
  170.  
  171.  
  172.                 strAPI = strAPI + fString; 
  173.  
  174.  
  175.  
  176.                 XmlTextReader hfXMLReader = new XmlTextReader(strAPI); 
  177.  
  178.  
  179.  
  180.                 DataSet ds = new DataSet(); 
  181.  
  182.  
  183.  
  184.                 ds.ReadXml(hfXMLReader); 
  185.  
  186.                 //读取歌曲名称 
  187.  
  188.                 string strDecode =  
  189.  
  190.                     ds.Tables["data"].Rows[0]["decode"].ToString().Replace("\n""");           
  191.  
  192.                 //读取歌曲编码 
  193.  
  194.                 string strEncode =  
  195.  
  196.                     ds.Tables["data"].Rows[0]["encode"].ToString().Replace("\n""");         
  197.  
  198.                 //读取歌词ID 
  199.  
  200.                 string strLrc =  
  201.  
  202.                     ds.Tables["data"].Rows[0]["lrcid"].ToString().Replace("<br />""");               
  203.  
  204.  
  205.  
  206.                 string strPath = ""
  207.  
  208.  
  209.  
  210.                 string strExt = ""
  211.  
  212.  
  213.  
  214.                 string strPre = strEncode.Split("/".ToCharArray()); 
  215.  
  216.                 //赋值MP3真正地址 
  217.  
  218.                 strPath = strEncode.Replace(strPre[strPre.Length - 1], strDecode);           
  219.  
  220.                 //歌词基本地址 
  221.  
  222.                 string strLrcPath = "http://box.zhangmen.baidu.com/bdlrc/";                  
  223.  
  224.  
  225.  
  226.                 if (strLrc == "0"
  227.  
  228.                 { 
  229.  
  230.                     strLrc = "暂无歌词"
  231.  
  232.                 } 
  233.  
  234.                 else 
  235.  
  236.                 { 
  237.  
  238.                     strLrc = strLrcPath + (Int32.Parse(strLrc) / 100).ToString() +  
  239.  
  240.                         "/" + strLrc + ".lrc"
  241.  
  242.                 } 
  243.  
  244.  
  245.  
  246.                 switch (ds.Tables["data"].Rows[0]["type"].ToString()) 
  247.  
  248.                 { 
  249.  
  250.                     case "1"
  251.  
  252.                         strExt = "rm"
  253.  
  254.                         break
  255.  
  256.                     case "0"
  257.  
  258.                         strExt = "mp3"
  259.  
  260.                         break
  261.  
  262.                     case "2"
  263.  
  264.                         strExt = "wma"
  265.  
  266.                         break
  267.  
  268.                 } 
  269.  
  270.  
  271.  
  272.                 if (strEncode == "nothing"
  273.  
  274.                 { 
  275.  
  276.                     return "nothing"
  277.  
  278.                 } 
  279.  
  280.  
  281.  
  282.                 return strEncode + " " + strDecode + " " + 
  283.  
  284.                     strExt + " " + strLrc + " " + strPath; 
  285.  
  286.             } 
  287.  
  288.             catch 
  289.  
  290.             { 
  291.  
  292.                 return GetMP3URL(fString); 
  293.  
  294.             } 
  295.  
  296.         } 
  297.  
  298.  
  299.  
  300.         private void button2_Click(object sender, EventArgs e) 
  301.  
  302.         { 
  303.  
  304.             string tempstr = ""
  305.  
  306.  
  307.  
  308.             for (int i = 1; i < 11; i++) 
  309.  
  310.             { 
  311.  
  312.                 tempstr += "1<<" + i.ToString() + ": " +  
  313.  
  314.                     (1 << i).ToString() + "\r\n"
  315.  
  316.             } 
  317.  
  318.  
  319.  
  320.             MessageBox.Show(tempstr); 
  321.  
  322.         } 
  323.  
  324.  
  325.  
  326.         private void button2_Click_1(object sender, EventArgs e) 
  327.  
  328.         { 
  329.  
  330.             this.axWindowsMediaPlayer1.URL = textBox3.Text; 
  331.  
  332.         } 
  333.  
  334.     } 
  335.  
  • 上一篇资讯: C#文本处理(字符)
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师