HI,
I need to add a music player in my web page, i had written some code to paly the file,
but it is not working, i can't find tha mistake where it is, can any one help to find the answer.
thank u.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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></title>
<script type="text/javascript">
var oldgridSelectedColor;
function setMouseOverColor(element) {
oldgridSelectedColor = element.style.backgroundColor;
element.style.backgroundColor = '#dcdcdc';
element.style.cursor = 'hand';
}
function setMouseOutColor(element) {
element.style.backgroundColor = oldgridSelectedColor;
element.style.textDecoration = 'none';
}
</script>
<style type="text/css">
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table>
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional" ChildrenAsTriggers="False">
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="grid"
EventName="Load">
</asp:AsyncPostBackTrigger>
</Triggers>
<ContentTemplate>
<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" id="player" class="musicplayer-media">
<param name="url" value= "<% =mySrc %>" />
<param name="src" value="<% =mySrc %>" />
<param name="name" value="musicplayer" />
<param name="showcontrols" value="true" />
<param name="animationatStart" value="true" />
<param name="volume" value="0" />
<!--[if !IE]>-->
<object type="video/x-ms-wmv" data="<% =mySrc %>" class="musicplayer-media">
<param name="src" value="<% =mySrc %>" />
<param name="name" value="musicplayer" />
<param name="autostart" value="true" />
<param name="controller" value="true" />
<param name="volume" value="0" />
</object>
<!--<![endif]-->
</object>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="grid" runat="server" BackColor="#CC9900" ForeColor="#663300"
onrowdatabound="grid_RowDataBound"
onselectedindexchanged="grid_SelectedIndexChanged" DataKeyNames="songname">
<Columns>
<asp:ButtonField CommandName="Select" Text="Play" />
</Columns>
<SelectedRowStyle BackColor="#66CCFF" BorderColor="Black" BorderStyle="Solid" />
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
and cs page is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Text;
public partial class Default2 : System.Web.UI.Page
{
public string mySrc;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getSongName();
}
}
public void getSongName()
{
DirectoryInfo di = new DirectoryInfo("C:/tes/");
if (di.Exists == true)
{
DataTable dt = new DataTable();
dt.Columns.Add("SongName");
foreach (FileInfo fi in di.GetFiles("*.mp3", SearchOption.AllDirectories))//get filename from this directory
{
DataRow dr = dt.NewRow();
dr["SongName"] = fi.Name;//show only song name excluding path
dt.Rows.Add(dr);
}
//grid.Columns[1].HeaderText = "Here are my favourite songs:";
grid.DataSource = dt;
grid.DataBind();
}
}
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";
}
protected void grid_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:/tes/");
mySrc = di + grid.SelectedDataKey.Values["songname"].ToString();
}
}