flash_uk Posted November 9, 2003 Posted November 9, 2003 Hi all Can anyone help me with this issue. I am trying to build a webpage which lists a number of mp3 files with a button for each file in the list. When you press the button,I want the relevant mp3 to be played on the embedded media player on the page. I have attached the code below which shows this for an example. Question is, when the button is pressed, how do I pass the name of the mp3 file to the embedded media player? Thanks for any pointers. Flash EXAMPLE: <%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Data" %> <html> <script language="VB" runat="server"> Sub Page_load(Sender As Object, E As EventArgs) dim ds as dataset = new dataset("mydataset") dim dtable as datatable = ds.tables.add("Music") Dim dCola As DataColumn = dtable.Columns.Add("Ref", Type.GetType("System.Int32")) Dim dColb As DataColumn = dtable.Columns.Add("Artist", Type.GetType("System.String")) Dim dColc As DataColumn = dtable.Columns.Add("Track", Type.GetType("System.String")) dim dr as datarow = dtable.newrow() dr(0)=1 dr(1)="DJ Tiesto" dr(2)="Urban Train" dtable.rows.add(dr) DataGrid1.DataSource = ds.Tables("music").DefaultView DataBind() end sub sub Datagrid1_ItemCommand(obj as object, e as _ DataGridCommandEventArgs) DataGrid1.SelectedIndex = e.Item.ItemIndex DataBind() end sub </script> <body> <form runat="server"> <asp:DataGrid id="DataGrid1" runat="server" BorderColor="black" GridLines="Vertical" cellpadding="4" cellspacing="0" width="450" Font-NameFont-Names="Arial" Font-Size="8pt" ShowFooter="True" HeaderStyle-BackColor="#cccc99" FooterStyle-BackColor="#cccc99" ItemStyle-BackColor="#ffffff" AlternatingItemStyle-Backcolor="#cccccc" AutoGenerateColumns="false" OnItemCommand="DataGrid1_ItemCommand"> <Columns> <asp:TemplateColumn HeaderText="Name"> <ItemTemplate> <asp:Label id="Name" runat="server" Text='<%# Container.DataItem("Artist")& _ " " & Container.DataItem("Track") %>'/> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn HeaderText="Ref" DataField="Ref"/> <asp:BoundColumn HeaderText="Artist" DataField="Artist"/> <asp:BoundColumn HeaderText="Track" DataField="Track" /> <asp:ButtonColumn HeaderText="Play?" text="Play" CommandName="item" ButtonType="PushButton"/> </Columns> </asp:DataGrid> </form> <OBJECT ID="mediaPlayer" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="http://activex.microsoft.com/activex/ controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" STANDBY="Loading Microsoft Windows Media Player components..." TYPE="application/x-oleobject"> <PARAM NAME="fileName" VALUE=""> <PARAM NAME="animationatStart" VALUE="true"> <PARAM NAME="transparentatStart" VALUE="true"> <PARAM NAME="autoStart" VALUE="false"> <PARAM NAME="showControls" VALUE="true"> </OBJECT> </body> </html> Quote
knea Posted February 28, 2005 Posted February 28, 2005 Did you find a solution?? Hi, Did u find a solution for this? Any help would be appreciated.. Thanks Knea Hi all Can anyone help me with this issue. I am trying to build a webpage which lists a number of mp3 files with a button for each file in the list. When you press the button,I want the relevant mp3 to be played on the embedded media player on the page. I have attached the code below which shows this for an example. Question is, when the button is pressed, how do I pass the name of the mp3 file to the embedded media player? Thanks for any pointers. Flash EXAMPLE: <%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Data" %> <html> <script language="VB" runat="server"> Sub Page_load(Sender As Object, E As EventArgs) dim ds as dataset = new dataset("mydataset") dim dtable as datatable = ds.tables.add("Music") Dim dCola As DataColumn = dtable.Columns.Add("Ref", Type.GetType("System.Int32")) Dim dColb As DataColumn = dtable.Columns.Add("Artist", Type.GetType("System.String")) Dim dColc As DataColumn = dtable.Columns.Add("Track", Type.GetType("System.String")) dim dr as datarow = dtable.newrow() dr(0)=1 dr(1)="DJ Tiesto" dr(2)="Urban Train" dtable.rows.add(dr) DataGrid1.DataSource = ds.Tables("music").DefaultView DataBind() end sub sub Datagrid1_ItemCommand(obj as object, e as _ DataGridCommandEventArgs) DataGrid1.SelectedIndex = e.Item.ItemIndex DataBind() end sub </script> <body> <form runat="server"> <asp:DataGrid id="DataGrid1" runat="server" BorderColor="black" GridLines="Vertical" cellpadding="4" cellspacing="0" width="450" Font-NameFont-Names="Arial" Font-Size="8pt" ShowFooter="True" HeaderStyle-BackColor="#cccc99" FooterStyle-BackColor="#cccc99" ItemStyle-BackColor="#ffffff" AlternatingItemStyle-Backcolor="#cccccc" AutoGenerateColumns="false" OnItemCommand="DataGrid1_ItemCommand"> <Columns> <asp:TemplateColumn HeaderText="Name"> <ItemTemplate> <asp:Label id="Name" runat="server" Text='<%# Container.DataItem("Artist")& _ " " & Container.DataItem("Track") %>'/> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn HeaderText="Ref" DataField="Ref"/> <asp:BoundColumn HeaderText="Artist" DataField="Artist"/> <asp:BoundColumn HeaderText="Track" DataField="Track" /> <asp:ButtonColumn HeaderText="Play?" text="Play" CommandName="item" ButtonType="PushButton"/> </Columns> </asp:DataGrid> </form> <OBJECT ID="mediaPlayer" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="http://activex.microsoft.com/activex/ controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" STANDBY="Loading Microsoft Windows Media Player components..." TYPE="application/x-oleobject"> <PARAM NAME="fileName" VALUE=""> <PARAM NAME="animationatStart" VALUE="true"> <PARAM NAME="transparentatStart" VALUE="true"> <PARAM NAME="autoStart" VALUE="false"> <PARAM NAME="showControls" VALUE="true"> </OBJECT> </body> </html> Quote
flash_uk Posted March 17, 2005 Author Posted March 17, 2005 I did! Take a look at the code below. The list is now pulled from an access database which contains a table with the following fields: ID Ref Artist Track Mix Filename Pathname Filesize I basically put a hidden label on the page (Filehide), and when the button gets pressed, the label gets updated with the URL of the track. The filename parameter passed to the player now refers to the value of the label: <PARAM NAME="fileName" VALUE="<%=FileHide.Text %>" Hope this helps. F =============CODE BELOW========================== <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script runat="server"> Sub Page_Load(sender as Object, e as EventArgs) If Not Page.IsPostBack BindData() End If End Sub Sub BindData() '1. Create a connection Const strConnStr as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\music3.mdb" Dim objConn as New OleDbConnection(strConnStr) objConn.Open() '2. Create a command object for the query Const strSQL as String = "SELECT * FROM List" Dim objCmd as New OleDbCommand(strSQL, objConn) '3. Create/Populate the DataReader Dim objDR as OleDbDataReader objDR = objCmd.ExecuteReader() dgTracks.DataSource = objDR dgTracks.DataBind() objConn.Close() End Sub sub dgTracks_ItemCommand(obj as object, e as _ DataGridCommandEventArgs) FileHide.Text = e.Item.cells(1).text end sub </script> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="660" border="0"> <tr> <td width="330" height="120" background="back1.png"><table width="330" border="0"> <tr> <td colspan="13"><font color="#000000" size="2" face="Tahoma"><strong>Browse Artist</strong></font></td> </tr> <tr align="center"> <td><font color="#000000" size="2" face="Tahoma"><a href="m_browseartist.aspx?searchletter=A">A</a></font></td> <td><font color="#000000" size="2" face="Tahoma">B</font></td> <td><font color="#000000" size="2" face="Tahoma">C</font></td> <td><font color="#000000" size="2" face="Tahoma">D</font></td> <td><font color="#000000" size="2" face="Tahoma">E</font></td> <td><font color="#000000" size="2" face="Tahoma">F</font></td> <td><font color="#000000" size="2" face="Tahoma">G</font></td> <td><font color="#000000" size="2" face="Tahoma">H</font></td> <td><font color="#000000" size="2" face="Tahoma">I</font></td> <td><font color="#000000" size="2" face="Tahoma">J</font></td> <td><font color="#000000" size="2" face="Tahoma">K</font></td> <td><font color="#000000" size="2" face="Tahoma">L</font></td> <td><font color="#000000" size="2" face="Tahoma">M</font></td> </tr> <tr align="center"> <td><font color="#000000" size="2" face="Tahoma">N</font></td> <td><font color="#000000" size="2" face="Tahoma">O</font></td> <td><font color="#000000" size="2" face="Tahoma">P</font></td> <td><font color="#000000" size="2" face="Tahoma">Q</font></td> <td><font color="#000000" size="2" face="Tahoma">R</font></td> <td><font color="#000000" size="2" face="Tahoma">S</font></td> <td><font color="#000000" size="2" face="Tahoma">T</font></td> <td><font color="#000000" size="2" face="Tahoma">U</font></td> <td><font color="#000000" size="2" face="Tahoma">V</font></td> <td><font color="#000000" size="2" face="Tahoma">W</font></td> <td><font color="#000000" size="2" face="Tahoma">X</font></td> <td><font color="#000000" size="2" face="Tahoma">Y</font></td> <td><font color="#000000" size="2" face="Tahoma">Z</font></td> </tr> <tr align="center"> <td><font color="#000000" size="2" face="Tahoma">1</font></td> <td><font color="#000000" size="2" face="Tahoma">2</font></td> <td><font color="#000000" size="2" face="Tahoma">3</font></td> <td><font color="#000000" size="2" face="Tahoma">4</font></td> <td><font color="#000000" size="2" face="Tahoma">5</font></td> <td><font color="#000000" size="2" face="Tahoma">6</font></td> <td><font color="#000000" size="2" face="Tahoma">7</font></td> <td><font color="#000000" size="2" face="Tahoma">8</font></td> <td><font color="#000000" size="2" face="Tahoma">9</font></td> <td><font color="#000000" size="2" face="Tahoma">0</font></td> <td><font color="#000000" size="2" face="Tahoma"> </font></td> <td><font color="#000000" size="2" face="Tahoma"> </font></td> <td><font color="#000000" size="2" face="Tahoma"> </font></td> </tr> </table></td> <td><table width="330" border="0"> <tr> <td><font color="#000000" size="2" face="Tahoma">Track info</font></td> </tr> <tr> <td height="60"><OBJECT height=40 ID="mediaPlayer" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="http://activex.microsoft.com/activex/ controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" STANDBY="Loading Microsoft Windows Media Player components..." TYPE="application/x-oleobject"> <PARAM NAME="fileName" VALUE="<%=FileHide.Text %>" > <PARAM NAME="animationatStart" VALUE="true"> <param name="uiMode" value="full"> <PARAM NAME="transparentatStart" VALUE="true"> <PARAM NAME="autoStart" VALUE="false"> <PARAM NAME="showControls" VALUE="true"> </OBJECT> </td> </tr> </table></td> </tr> <tr valign="top"> <td height="350" colspan="2"><form runat="server"> <div style="position:relative; vertical-align: top; height:300px; overflow:auto;"> <asp:DataGrid runat="server" id="dgTracks" AutoGenerateColumns="False" ShowHeader="False" BorderColor="black" GridLines="Vertical" cellpadding="4" cellspacing="0" width="400" Font-NameFont-Names="Arial" Font-Size="8pt" ShowFooter="True" HeaderStyle-BackColor="#cccc99" FooterStyle-BackColor="#cccc99" ItemStyle-BackColor="#ffffff" AlternatingItemStyle-Backcolor="#cccccc" OnItemCommand="dgTracks_ItemCommand"> <Columns> <asp:BoundColumn HeaderText="Artist" DataField="Artist" /> <asp:BoundColumn HeaderText="Pathname" DataField="Pathname" /> <asp:BoundColumn HeaderText="Track" DataField="Track"/> <asp:BoundColumn HeaderText="Mix" DataField="Mix" /> <asp:ButtonColumn HeaderText="Play?" text="Play" CommandName="item" ButtonType="PushButton"/> </Columns> </asp:DataGrid> </div> <asp:Label id="FileHide" runat ="server" Visible="False"/> </form></td> </tr> </table> </body> </html> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.