I have a problem in playing audio and video songs. The code is given below. Please help.
There is no error in entire code but video is not playing in repeater, the code of repeater given below:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<object id="player" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"
height="170" width="300">
<param name="url" value='<%# "VideoHandler.ashx?id=" + Eval("ID") %>'/>
<param name="showcontrols" value="true" />
<param name="autostart" value="true" />
</object>
<script type="text/javascript" src="fixit.js"></script>
</ItemTemplate>
</asp:Repeater>
so please give me solution. thanks...
code of ashx page:
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public class VideoHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
string connectionString = ConfigurationManager.ConnectionStrings["uploadConnectionString"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT savevideo, Video_Name FROM Videos WHERE ID = @id", connection);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = context.Request.QueryString["id"];
try
{
connection.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
if (reader.HasRows)
{
while (reader.Read())
{
context.Response.ContentType = reader["Video_Name"].ToString();
context.Response.WriteFile(reader["savevideo"].ToString());
}
}
}
finally
{
connection.Close();
}
}
public bool IsReusable
{
get {
return false;
}
}
}
code of aspx page............
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Media;
public partial class MemberAudioVideoUpload : System.Web.UI.Page
{
byte[] buffer;
SqlConnection connection;
string loc = "";
gen_fn.connection_class fns = new gen_fn.connection_class();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user_id"] == null || Session["roll"] == null)
{
string err = "Oops! Session Expired. Please Login Again to Continue";
Response.Redirect("Login.aspx?err=" + err);
}
if (!Page.IsPostBack)
{
bind();
}
}
private DataTable GetVideoInfo()
{
string connectionString = ConfigurationManager.ConnectionStrings["uploadConnectionString"].ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Videos where user_id='" + Session["user_id"].ToString() + "'", connectionString);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
private DataTable GetSpecificVideo(object i)
{
string connectionString = ConfigurationManager.ConnectionStrings["uploadConnectionString"].ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter("SELECT savevideo, ID FROM Videos WHERE ID = @id", connectionString);
adapter.SelectCommand.Parameters.Add("@id", SqlDbType.Int).Value = (int)i;
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
public void bind()
{
GridView1.DataSource = GetVideoInfo();
GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int i = (int)GridView1.DataKeys[e.RowIndex].Value;
fns.execut_qry("delete from Videos where ID=" + i + "");
bind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "run")
{
lbl_err.Text = "";
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
Label lbl = new Label();
lbl = (Label)row.Cells[0].FindControl("lbl");
string st = lbl.Text;
int var = Convert.ToInt16(st);
Repeater1.DataSource = GetSpecificVideo(var);
Repeater1.DataBind();
}
}
protected void btn_submit_Click(object sender, ImageClickEventArgs e)
{
save_videos();
if (FileUpload1.HasFile && FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
HttpPostedFile file = FileUpload1.PostedFile;
buffer = new byte[file.ContentLength];
int bytesReaded = file.InputStream.Read(buffer, 0, FileUpload1.PostedFile.ContentLength);
if (bytesReaded > 0)
{
try
{
string connectionString = ConfigurationManager.ConnectionStrings["uploadConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand
("INSERT INTO Videos (Video_Name, Video_Size,user_id,dated,album,artist,savevideo,status) VALUES (@videoName, @videoSize, @user_id, @dated, @album, @artist, @savevideo, @status)", connection);
cmd.Parameters.Add("@videoName", SqlDbType.NVarChar).Value = FileUpload1.FileName;
cmd.Parameters.Add("@videoSize", SqlDbType.BigInt).Value = file.ContentLength;
cmd.Parameters.Add("@user_id", SqlDbType.VarChar, 500).Value = Session["user_id"].ToString();
cmd.Parameters.Add("@dated", SqlDbType.VarChar, 500).Value = System.DateTime.Now.ToLongDateString();
cmd.Parameters.Add("@album", SqlDbType.VarChar, 500).Value = txt_album.Text;
cmd.Parameters.Add("@artist", SqlDbType.VarChar, 500).Value = txt_artist.Text;
cmd.Parameters.Add("@savevideo", SqlDbType.VarChar, 500).Value = loc;
cmd.Parameters.Add("@status", SqlDbType.VarChar, 500).Value = "pending";
using (connection)
{
connection.Open();
int i = cmd.ExecuteNonQuery();
lbl_err.Text = "File uploaded successfully, " + i.ToString() + " rows affected";
txt_album.Text = "";
txt_artist.Text = "";
bind();
}
}
catch (Exception ex)
{
lbl_err.Text = ex.Message.ToString();
}
}
}
else
{
lbl_err.Text = "Choose a valid video file";
}
}
public void save_videos()
{
string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
fns.check_valid_path(Server.MapPath("13/" + Session["user_id"].ToString() + "/video"));
string SaveLocation = Server.MapPath("13/" + Session["user_id"].ToString() + "/video/" + Session["user_id"].ToString().Trim() + fn);
if (!Directory.Exists(SaveLocation))
{
try
{
FileUpload1.PostedFile.SaveAs(SaveLocation);
SaveLocation = ("13/" + Session["user_id"].ToString() + "/video/" + Session["user_id"].ToString().Trim() + fn);
loc = SaveLocation;
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
else
{
lbl_err.Text = "File Name Already Exists";
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = GetVideoInfo();
GridView1.DataBind();
}
}
code of html page:
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="MemberAudioVideoUpload.aspx.cs" Inherits="MemberAudioVideoUpload" %>
<%@ Register Src="~/redhorbar.ascx" TagName="redbar" TagPrefix="uc1" %>
<%@ Register Src="~/redfooter.ascx" TagName="footer" TagPrefix="uc2" %>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js"></script>
<a name="ytplayer"></a>
<div id="ytplayer_div">You need Flash player 8+ and JavaScript enabled to view this video.</div>
<script type="text/javascript">
swfobject.embedSWF(
'http://www.youtube.com/v/INSERT_YOUTUBE_VIDEO_ID_1_HERE&enablejsapi=1&rel=0&fs=1',
'ytplayer_div',
'425',
'344',
'8',
null,
null,
{
allowScriptAccess: 'always',
allowFullScreen: 'true'
},
{
id: 'ytplayer_object'
}
);
</script>
<script type="text/javascript">
function ytplayer_loadvideo(id) {
var o = document.getElementById('ytplayer_object');
if (o) {
o.loadVideoById(id);
}
}
</script>
<%----%>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ING4Music | MemberAudioVideoUpload</title>
<link href="Css/Css.css" rel="stylesheet" type="text/css" />
<link href="Css/Css.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-image:url('images/Red_bgcontenEvent.jpg'); background-attachment:fixed;background-repeat:no-repeat">
<form id="form1" runat="server">
<table width="874" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><uc1:redbar ID="redbar" runat="server" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="redEvent_contenmiddel"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><img src="images/Red_manageAlbum_member-regist-c.jpg" alt="" width="170" height="65" /></td>
<td width="27" rowspan="2" class="Redshop_leftmenu"> </td>
<td width="677" valign="top"><img src="images/Red_manageAlbum_member-regis-04.jpg" alt="" width="677" height="65" /></td>
</tr>
<tr>
<td height="508" valign="top">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
height="390" width="170">
<param name="movie" value="memberMenu.swf">
<param name="quality" value="high">
<embed height="390" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high"
src="memberMenu.swf" type="application/x-shockwave-flash" width="170"></embed></object><script type="text/javascript" src="fixit.js"></script></td>
<td width="677" height="508" valign="top"><table style="margin:0px 0px 5px 15px" width="640" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" class="Red_borderViewProfile " style="height: 21px"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="324" class="Red_borderrightFovourite2"><table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td style="width: 128px; height: 22px;" align="center" class="Red_borderProfileEdit">
<asp:Label ID="lab1" Text="Upload" runat="server" CssClass="Red_textyelowViewProfile" Width="65px" Font-Bold="True" Font-Size="Medium"></asp:Label>
</td>
<td style="height: 22px">
<asp:FileUpload ID="FileUpload1" runat="server" CssClass="Red_Photoupload_browse" Width="261px" />
</td>
</tr>
<tr>
<td style="width: 128px; height: 22px;" align="center" class="Red_borderProfileEdit">
<asp:Label ID="Label1" Text="Artist" runat="server" CssClass="Red_textyelowViewProfile" Width="65px" Font-Bold="True" Font-Size="Medium"></asp:Label>
</td>
<td style="height: 22px">
<asp:TextBox ID="txt_artist" CssClass="Red_field1ProfieldEdit" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 128px; height: 22px;" align="center" class="Red_borderProfileEdit">
<asp:Label ID="Label2" Text="Album" runat="server" CssClass="Red_textyelowViewProfile" Width="65px" Font-Bold="True" Font-Size="Medium"></asp:Label>
</td>
<td style="height: 22px">
<asp:TextBox ID="txt_album" CssClass="Red_field1ProfieldEdit" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 128px">
</td>
<td>
<asp:ImageButton ID="btn_submit" ImageUrl="~/images/Red_submit3.jpg" runat="server" OnClick="btn_submit_Click" />
</td>
</tr>
</table>
<asp:Label ID="lbl_err" runat="server" CssClass="Red_textyelowViewProfile" Width="100%" Font-Bold="True"></asp:Label></td></tr>
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<object id="player" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"
height="170" width="300">
<param name="url" value='<%# "VideoHandler.ashx?id=" + Eval("ID") %>'/>
<param name="showcontrols" value="true" />
<param name="autostart" value="true" />
</object>
<script type="text/javascript" src="fixit.js"></script>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
<tr>
<td class="Red_borderProfileEdit" align="center" valign="top">
<asp:GridView ID="GridView1" runat="server" BorderStyle="None" BorderWidth="1px" CellPadding="4"
GridLines="Vertical" CssClass="Red_textyelowViewProfile" DataKeyNames="ID" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" AutoGenerateColumns="False" Width="612px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:templatefield>
<ItemTemplate>
<table>
<tr>
<td>
<asp:ImageButton ID="img" ImageUrl="paly.gif" AlternateText="play" CommandName="run" runat="server" onClick="ytplayer_loadvideo( '2' )" />
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="link" CssClass="Red_textyelowViewProfile" Text='<%# Bind("Video_Name") %>' CommandName="run" runat="server"></asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl" Text='<%# Bind("ID") %>' Visible="false" runat="server"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:templatefield>
<asp:TemplateField HeaderText="Video Name">
<ItemTemplate>
<table>
<tr>
<td class="Red_textprofileEdit2">
<%#DataBinder.Eval(Container.DataItem,"Video_name") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Video Size">
<ItemTemplate>
<table>
<tr>
<td class="Red_textprofileEdit2">
<%#DataBinder.Eval(Container.DataItem,"Video_size") %> bytes
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Artist">
<ItemTemplate>
<table>
<tr>
<td class="Red_textprofileEdit2">
<%#DataBinder.Eval(Container.DataItem,"artist") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Album">
<ItemTemplate>
<table>
<tr>
<td class="Red_textprofileEdit2">
<%#DataBinder.Eval(Container.DataItem,"album") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<table>
<tr>
<td class="Red_textprofileEdit2">
<%#DataBinder.Eval(Container.DataItem,"status") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Uploaded By">
<ItemTemplate>
<table>
<tr>
<td class="Red_textprofileEdit2">
<%#DataBinder.Eval(Container.DataItem,"user_id") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Uploaded On">
<ItemTemplate>
<table>
<tr>
<td class="Red_textprofileEdit2">
<%#DataBinder.Eval(Container.DataItem,"dated") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" >
<ControlStyle CssClass="Red_textyelowViewProfile" />
</asp:CommandField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr><td> <uc2:footer ID="footer" runat="server" /></td></tr>
</table>
</form>
</body>
</html>