音乐播放器插件的使用

一、此音乐播放器插件的官网演示和下载地址:http://www.52player.com/Demos/14MP3ListPlayer/

二、代码演示

   1.前台

   

 1 <body>
 2     <form id="form1" runat="server">
 3     <div>
 4     
 5         <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="360" height="26">
 6           <param name="movie" value="/14Mp3ListPlayer/player_S.swf?listfile= <%=xmlname%>" />
 7           <param name="quality" value="high" />
 8           <param name="allowScriptAccess" value="always" />
 9          <param name="wmode" value="transparent"/>
10          <embed src="/14Mp3ListPlayer/player_S.swf?listfile= <%=xmlname%>" quality="high" type="application/x-shockwave-flash"
11           WMODE="transparent" width="360" height="26" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" />
12         </object>
13         
14     </div>
15     </form>
16 </body>

2.后台

 1 namespace MusicPlayer
 2 {
 3     public partial class MusicPlayer_page : System.Web.UI.Page
 4     {
 5         public string murl = "";
 6         public string title = "";
 7         public string info = "";
 8         public string FileTotalName = "";
 9         public string xmlname = "";
10 
11         protected void Page_Load(object sender, EventArgs e)
12         {
13             if (!IsPostBack)
14             {
15                 //这三个取是数据库的值
16                 murl = "/Music/foam.mp3";
17                 title = "泡沫—邓紫棋";
18                 info = "aaaa啊啊啊啊啊啊啊啊啊啊啊啊";
19 
20                 //取随机数,得到xml文件的名字
21                 string[] s1 = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };//字符列表
22                 Random rand = new Random();
23                 string str = s1[rand.Next(0, s1.Length)] + s1[rand.Next(0, s1.Length)] + s1[rand.Next(0, s1.Length)] + s1[rand.Next(0, s1.Length)] + s1[rand.Next(0, s1.Length)];
24                 xmlname = str + ".xml";
25 
26                 FileTotalName = Server.MapPath(".") + "\" + xmlname;//得到xml文件额相对路径
27                 WriteXml(FileTotalName, murl, title, info);
28             }
29         }
30         //创建XML
31         public void WriteXml(string FileName, string file, string title, string artist)
32         {
33             //初始化XML文档操作类
34             XmlDocument myXml = new XmlDocument();
35             XmlNode node1 = myXml.CreateXmlDeclaration("1.0", "utf-8", "");
36             myXml.AppendChild(node1);
37             //创建根节点  
38             XmlNode root = myXml.CreateElement("player");
39             myXml.AppendChild(root);
40             //添加第二层节点
41             XmlElement xel = myXml.CreateElement("playlist");
42             root.AppendChild(xel);
43             //添加第三层节点
44             XmlElement xel2 = myXml.CreateElement("track");
45             xel.AppendChild(xel2);
46 
47             CreateNode(myXml, xel2, "file", file);
48             CreateNode(myXml, xel2, "title", title);
49             CreateNode(myXml, xel2, "artist", artist);
50             try
51             {
52                 myXml.Save(FileName);
53             }
54             catch (Exception e)
55             {
56                 throw (e);
57             }
58         }
59 
60         public void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value)
61         {
62             XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
63             node.InnerText = value;
64             parentNode.AppendChild(node);
65         }
66 
67     }
68 }
三、效果截图



原文地址:https://www.cnblogs.com/ElvisZhongShao/p/4360294.html