Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys... I have a gridview inwhich I am showing the wave file paths along with the button stating "Play Now". Now everything is working OK i.e. I'm getting the records (using RowCommand method of gridview) and showing the paths etc. But I am unable to play these sounds using <object> tag embedded in asp.net using the literal control. Here is what I am doing
<script runat="server">
    void OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Play Now"))
        {
            int index = Convert.ToInt32(e.CommandArgument); //this will get rowid from gridview
            GridViewRow row = gridCalls.Rows[index];
            txt1.Text = row.Cells[5].Text; // second column in the sql server database

            myLiteral.Text = "<object>";
            myLiteral.Text += "<param name='autostart' value='true'>";
            myLiteral.Text += "<param name='src' value='Likh Raha.mp3'>";
            myLiteral.Text += "<param name='autoplay' value='true'>";
            myLiteral.Text += "<param name='controller' value='true'>";
            myLiteral.Text += "<embed src='Likh Raha.mp3' controller='true' autoplay='true' autostart='True' type='audio/wav' />";
            myLiteral.Text += "</object>";
        }
    }
Posted
Updated 2-Mar-11 11:27am
v2
Comments
Dave Kreskowiak 2-Mar-11 16:17pm    
I haven't done much web development, but aren't you missing a classid in the object tag to specify the player that's going to play the MP3?

Hi If you need to render this object at runtime create a custom control which reders this object.
You may add that object to grid view cells control collection.

Here is the link for a custom class for playing sound

http://www.vbdotnetheaven.com/UploadFile/scottlysle/PlaySoundsInASPX09032006083212AM/PlaySoundsInASPX.aspx[^]
 
Share this answer
 
Hello friend please use label control insted of literal.
Because in my application this code will running fine.
XML
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Play Now"))
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = gridCalls.Rows[index];
        string songname = row.Cells[5].Text; // second column in the sql server database
        StringBuilder str = new StringBuilder();
        str.Append("<object width='300px' height='300px'>");
        str.Append("<param name='autostart' value='true'>");
        str.Append("<param name='src' value='songs/" + songname + "'>");
        str.Append("<param name='autoplay' value='true'>");
        str.Append("<param name='controller' value='true'>");
        str.Append("<embed width='300px' height='300px' src='songs/" + songname + "' controller='true' autoplay='true' autostart='True' type='audio/wav' />");
        str.Append("</object>");

        LoadPlayer.Text = str.ToString();//here loadplayer is label control
    }
}
 
Share this answer
 
I think you're missing the command to add the literal control (myLiteral) to the collection of controls on your page. For example, if your gridview is on an asp panel labeled "pnl1", then after your "myLiteral.Text += "</object>"; line, you need a command that says "pnl1.Controls.Add(myLiteral)"
 
Share this answer
 
Comments
CHill60 18-Feb-15 4:53am    
I sincerely hope the OP hasn't waited for over 3 years for this response. Or to put it another way, posting solutions to years-old questions that have already had responses is likely to attract down-voting
AmbiguousName 2-Mar-15 9:11am    
Well thank you for your answer. May be this will be helpful to someone out there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900