Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
how to play .mp3 file by clicking the name of .mp3 file in gridview?in gridview all the name of .mp3 songs are available.i want if i will click the name of .mp3 file that mp3 song should play.please give instruction?

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <object id="video" height="300" width="300" classid="CLSID:6bf52a52-394a-11d3-b153-00c04f79faa6" visible="true">
        <param name="url" value="http://localhost:8222/WebSitePractice/Player/http://localhost:8222/WebSitePractice/Player/GUITAR.mp3"/> //here the value I need to pass this variable fileURL which is in cs page
        <param name="sendplaystatechangeevents" value="true" />
        <param name="autoStart" value="false"/>
        <param name="playcount" value="9999" />
    </object>

        <br />
        <asp:DataGrid ID="dgMusicList" runat="server" AutoGenerateColumns="False" OnItemCommand="dgMusicList_ItemCommand">
        <Columns>
            <asp:TemplateColumn HeaderText="PlayList">
                <ItemTemplate>
                <asp:Label ID="lblPlayList" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "FileName") %>'></asp:Label>
                </ItemTemplate>
                </asp:TemplateColumn>
            <asp:ButtonColumn  CommandName="PlayMusic" HeaderText="Play" Text="Play"></asp:ButtonColumn>
        </Columns>
    </asp:DataGrid>

    </div>
    </form>
</body>
</html>



.cs coding is

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Default8 : System.Web.UI.Page
{
string fileURL, FileName;
SqlConnection cn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=Q;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
cn.Open();
SqlCommand cmd = new SqlCommand("SELECT FileName from Ring", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dgMusicList.DataSource = ds;
dgMusicList.DataBind();

}
protected void dgMusicList_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "PlayMusic")
{
FileName = ((Label)e.Item.Cells[0].FindControl("lblPlayList")).Text;
}
SqlCommand cmd = new SqlCommand("SELECT FileContent from Ring where FileName = '" +FileName.ToString()+ "'", cn);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
fileURL = dr[0].ToString();
dr.Close();
}
}
Posted
Updated 9-Jul-11 23:35pm
v3
Comments
samaira joshi 23-Mar-13 7:14am    
pls suggest me something about its database. m trying it bt not getting it

try this link
MP3 in asp.net c# RSS[^]
 
Share this answer
 
Comments
Banajyotsna 10-Jul-11 5:22am    
sir it is not running
Hello Dear
you Can Do this:
if you have complete path of each .mp3 file which user click on it in DataGrid
you can do this:
Process.Start("FilePath");
 
Share this answer
 

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