Question

I have a small music site which you can see songs in a gridview and play/download them. Now I want to play though a embedded music player. There are so many embedded music players and examples when I googled it but most of them they just say with fixed URL of songs to play. I couldn't find out how to pass parameter to a embedded music player from the gridview that i currently have.

What I have now. Song_Name represents name of mp3 file in the Uploads folder which is in datatable.

        <asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="False" >
        <Columns>
         <asp:HyperLinkField DataNavigateUrlFields="Song_Name" Target="_blank"
            DataNavigateUrlFormatString='~/Uploads/{0}' Text="&lt;img src='Images/play.png' border='0'/&gt;" >             
         </asp:HyperLinkField>          
         </Columns>                
        </asp:GridView>

Code Behind

           On PageLoad
           Dim dtable = GetSong()
            gridview1.datasource = dtable
             gridview1.databind()

Simple Embedded Player code that I might use.

         <embed type=”application/x-shockwave-flash” flashvars=”audioUrl=MP3_FILE_URL”
          src=”http://www.google.com/reader/ui/3523697345-audio-player.swf” width=”400″ height=”27″ 
         quality=”best”></embed>

In this example, I have to pass filename which is Song_Name in the gridview + fixed url such as http://www.mysite.com/uploadds/Song_Name to audioUrl for the embedded player. How do i do it ? Basically, if a user click, play button on the gridview of each song, i want to use the embedded music player to play the song. Pls see girdview example. Playbutton is the hyperlink field as the code above. Sorry for poor english. :D

Thanks so much.

L

gridview example

Was it helpful?

Solution

No one answered my question. I am not sure if my question wasn't clear enough for people to understand. Well, I finally found a way around the problem. So i want to share my solution. Hope it helps to others who need to work with Gridview alot.

To achieve that, I have to put a hidden label field inside gridview as

    <ItemTemplate>
    <asp:Label ID="lblSongNam" Visible="false" runat="server" Text='<%#Eval("Song_Name") %>'></asp:Label>
    </ItemTemplate>

And you also need a empty Div where you want the embedded music player to appear as

    <div id="musicplayer"  runat="server"></div>

It is essential to put runat="server" property for Div.

In the code behind of Gridview rowcommand as

        Dim indexx As Integer = Convert.ToInt32(e.CommandArgument)
        Dim roww As GridViewRow = GridView1.Rows(indexx)
        Dim usernamee As String = Page.User.Identity.Name
        Dim Song_Namee As String = (DirectCast(roww.FindControl("lblSongNam"), Label)).Text
        Dim str As New StringBuilder()
        str.Append("<embed type='application/x-shockwave-flash'    flashvars='audioUrl=http://www.mysite.com/songs/")
        str.Append(Song_Namee)
        str.Append("&autoPlay=true' src='http://www.google.com/reader/ui/3523697345-audio-player.swf'")
        str.Append(" width='700' height='27' quality='best'></embed>")
        musicplayer.InnerHtml = str.ToString

In this example, i used google flash audio player but the player can be anything of course. It is quite handy way to manipulate HTML or Javascript code from asp.net code behind using StringBuilder and server side Div to use InnerHtml property of Div and change content at runtime.

Thanks all,

L

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top