frmWebMp3.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. namespace LYFZ.Software.MainBusiness.MicroShare
  8. {
  9. public class frmWebMp3 : LYFZ.Software.UI.MicroShare.frmWebMp3
  10. {
  11. public frmWebMp3() {
  12. this.Shown += frmWebMp3_Shown;
  13. this.dataGridViewEx1.CellMouseClick += dataGridViewEx1_CellMouseClick;
  14. this.FormClosed += frmWebMp3_FormClosed;
  15. }
  16. string musicPlay = "http://wx.lyfz.net/";
  17. void frmWebMp3_FormClosed(object sender, FormClosedEventArgs e)
  18. {
  19. this.webBrowser1.Url = new Uri(musicPlay+"music.html?audio=1");
  20. }
  21. void dataGridViewEx1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  22. {
  23. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  24. {
  25. DataGridViewRow row = this.dataGridViewEx1.Rows[e.RowIndex];
  26. if (row.Tag != null && row.Tag.ToString().Length>1)
  27. {
  28. this.webBrowser1.ScrollBarsEnabled = false;
  29. if (e.ColumnIndex == 2)
  30. {
  31. // LYFZ.WinAPI.CustomPublicMethod.RunStart(row.Tag.ToString());
  32. this.webBrowser1.Url = new Uri(musicPlay + "music.html?audio=" + row.Tag.ToString());
  33. }
  34. else if (e.ColumnIndex == 3)
  35. {
  36. WebMP3Path = row.Tag.ToString().Trim();
  37. Mp3Name = row.Cells[0].Value.ToString();
  38. this.webBrowser1.Url = new Uri(musicPlay + "music.html?audio=1");
  39. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  40. }
  41. }
  42. }
  43. }
  44. void frmWebMp3_Shown(object sender, EventArgs e)
  45. {
  46. BindMP3List();
  47. }
  48. string _webMP3Path = "";
  49. /// <summary>
  50. ///
  51. /// </summary>
  52. public string WebMP3Path
  53. {
  54. get { return _webMP3Path; }
  55. set { _webMP3Path = value; }
  56. }
  57. string mp3Name = "";
  58. public string Mp3Name
  59. {
  60. get { return mp3Name; }
  61. set { mp3Name = value; }
  62. }
  63. static dynamic TemplatesJson = null;
  64. void BindMP3List()
  65. {
  66. this.dataGridViewEx1.Rows.Clear();
  67. if (TemplatesJson == null)
  68. {
  69. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  70. {
  71. backgroundWorker.ReportProgress(0, "正在获取音乐...");
  72. try
  73. {
  74. string retTemplates = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(FrmMicroShare.domainName + "/music", Encoding.UTF8);
  75. TemplatesJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retTemplates);
  76. if (TemplatesJson.code != 0)
  77. {
  78. MessageBoxCustom.Show("获取网络音乐失败:" + TemplatesJson.info, backgroundWorker: backgroundWorker);
  79. TemplatesJson = null;
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. MessageBoxCustom.Show("获取网络音乐出错:" + ex.Message, backgroundWorker: backgroundWorker);
  85. }
  86. });
  87. }
  88. if (TemplatesJson != null)
  89. {
  90. foreach (var mp3 in TemplatesJson.data)
  91. {
  92. DataGridViewRow row = new DataGridViewRow();
  93. row.CreateCells(this.dataGridViewEx1);
  94. row.Cells[0].Value = mp3.title;
  95. row.Cells[1].Value = mp3.author;
  96. row.Cells[2].Value = "试听";
  97. row.Cells[3].Value = "选择";
  98. row.Tag = mp3.url;
  99. this.dataGridViewEx1.Rows.Add(row);
  100. }
  101. }
  102. }
  103. }
  104. }