Click here to Skip to main content
12,953,937 members (42,279 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
how to play a video file in asp.net with C# asp.net page link file save in database.
please replay ...
Posted 12-Jan-12 9:03am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Please have a look at the links provided:

Display videos in ASP.Net 2.0[^]
Streaming Media[^]

Slightly out of subject but these will also help you:
How do i use asp.net to display video from bytes in sql database[^]
Play video file from database through handler[^]

Good luck,
OI
  Permalink  
v2
Comments
thatraja 12-Jan-12 15:53pm
   
2nd link is my favorite one, 5!
Orcun Iyigun 12-Jan-12 17:56pm
   
Thanks thatraja :)
NandaKumer 13-Jan-12 1:16am
   
good links
Orcun Iyigun 13-Jan-12 2:28am
   
thank you Nanda.
Rajesh Anuhya 13-Jan-12 2:12am
   
Good answer , have my +5
Orcun Iyigun 13-Jan-12 2:29am
   
thank you Rajesh!
Tech Code Freak 6-Feb-12 6:32am
   
5up!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

If you have save path of video in database then you can play as

take a datalist and bind it with video url.
like
<asp:datalist id="DataList1" runat="server" repeatdirection="Horizontal" xmlns:asp="#unknown">
	RepeatColumns="4" BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" 
	 BorderWidth="1px" CellPadding="4" GridLines="Both"      
        onitemcommand="DataList1_ItemCommand1" Width="99%" 
        onselectedindexchanged="DataList1_SelectedIndexChanged">    
        <itemtemplate>              
           <asp:imagebutton id="Image1" runat="server" height="120px" width="180px" imageurl="~/temp/thumb.jpg" commandname="select" commandargument="<%#Eval("url") %>" /><br />
           <asp:linkbutton id="LinkButton2" runat="server" forecolor="Blue" onclick="<%#Eval("url") %>" commandname="select" commandargument="<%#Eval("url") %>"> <%#Eval("Video_Name") %></asp:linkbutton><br />
        </itemtemplate>
    </asp:datalist>
        <asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
        ConnectionString="<%$ ConnectionStrings:cnn %>" 
        SelectCommand="SELECT [Video_Name], [url] FROM [electronicmedia] order by sno desc ">
    </asp:sqldatasource>

and use embed tag to get player
<embed id='embed1' runat="server" name='mediaPlayer' type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'  displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='true' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='500' height='405'  designtimesp='5311' loop='false'>
 

on datalist itemcommand
protected void DataList1_ItemCommand1(object source, DataListCommandEventArgs e)
   {
       try
       {
           if (e.CommandName == "select")
           {
               string path = e.CommandArgument.ToString().Trim();
               embed1.Attributes.Add("src", e.CommandArgument.ToString().Trim());
               this.modal1.Show();
           }
       }
       catch (Exception ex)
       {
           Response.Write(ex.ToString());
       }
   }
  Permalink  
Comments
Chandrakant_Bhanu 18-Feb-12 3:47am
   
pls mail me this project i need this project for may current project actuly
i am confuse on this line this.modal1.Show(); this line genret error pls help me my contact email id is c.dahekar@gmail.com
Uma Shankar Patel 18-Feb-12 3:56am
   
modal1 is a Ajax ModalPoup extender to pop up player..
you can see Ajax ModalPoup extender on google
you do not need this, you can put embed code on panel,div.
Chandrakant_Bhanu 18-Feb-12 4:12am
   
which video format u use for this project
VyasRavi6776 23-Sep-12 8:37am
   
Hi..i have tried a lot...but video is not playing ..
i m showing my code here..

default.aspx

<embed id='embed1' runat="server" name='mediaPlayer' type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='true' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='500' height='405' designtimesp='5311' loop='false'>

</embed>

Default.cs

protected void Page_Load(object sender, EventArgs e)
{

embed1.Attributes.Add("src", "~/VIDEO/Ekla.mp4");


}

So please Do the needfull
Uma Shankar Patel 24-Sep-12 1:17am
   
when you run this,A player should show.I think problem is video not playing in player.
Right click on player.see properties=>see location
check if you get the correct location....
if it is wrong change it with src attribute
Willem Geerts 18-Mar-13 6:43am
   
I don't see anything of the video in firefox ? In chrome and internet expl. well
Is this normal?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

try this

<object type="video/x-ms-wmv" data="video\video.mpeg" width="420" height="340">
   <param name="url" value="video\video.mpeg"/>
   <param name="src" value="video\video.mpeg" />
   <param name="autostart" value="true" />
   <param name="sound" value="false" />
   <param name="controller" value="true" />
   </object>
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Step:1-VideoDemo.aspx
------
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    <table style="width: 400px;" border="0" cellpadding="2" cellspacing="3">
        <tr>
            <td style="width: 150px;" valign="top">
            </td>
            <td style="width: 200px;" valign="top" align="left">
                <asp:label id="lblMsg" cssclass="tdMessage" text="" runat="server" xmlns:asp="#unknown"></asp:label>
            </td>
        </tr>
        <tr>
            <td class="tdText" valign="top" align="left">
                <nobr> Select a file</nobr>
            </td>
            <td style="text-align: left;" valign="top">
                <asp:fileupload id="fUpload" runat="server" width="300px" xmlns:asp="#unknown"></asp:fileupload>
            </td>
        </tr>
        <tr>
            <td valign="top" align="left">
                <asp:button id="btnUpload" runat="server" text="Upload" onclick="btnUpload_Click" xmlns:asp="#unknown">
                </asp:button>
            </td>
            <td valign="top" align="left">
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">
                    width="200" height="100">
                    <param name="movie" value="<% =swfFileName%>">
                    <param name="quality" value="high">
                    <embed src="<%=swfFileName%>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer">
                        type="application/x-shockwave-flash" width="200" height="100">
                </embed></param></param></object>
            </td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html>

Step-2:(VideoDemo.aspx.cs)
-------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
 
namespace VideoDemo
{
    public partial class VDemo : System.Web.UI.Page
    {
        public string swfFileName;
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
        protected void btnUpload_Click(object sender, EventArgs e)
     {
        if (fUpload.FileContent.Length >0 && IsVaildFile())
        {
            string Path = GetUplaodImagePhysicalPath();
            DirectoryInfo dirUploadImage = new DirectoryInfo(Path);
            if (dirUploadImage.Exists == false)
            {
                dirUploadImage.Create();
            }
            string fileUrl = Path + fUpload.PostedFile.FileName;
            fUpload.PostedFile.SaveAs(fileUrl);
            swfFileName = "images/" + fUpload.PostedFile.FileName;
        }
    }
    private bool IsVaildFile()
    {
        string swfExt = System.IO.Path.GetExtension(fUpload.PostedFile.FileName);
        switch (swfExt)
        {
            case ".swf":
                return true;
            default:
            {
                    lblMsg.Text = "Please select only swf file.";
                    return false;
            }
        }
    }
 

    
    string GetUplaodImagePhysicalPath()
    {
        return System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "images\\";
    }
  
} 
    
}
  Permalink  
v2
Comments
Jitendra Kumar Gangwar 20-Mar-12 3:04am
   
thanks, your code working properly but i want to play .mp4 file in asp net.
jeta6561 24-May-12 0:32am
   
can you please send me project .. above describe code
210032278 11-Jul-13 21:55pm
   
i copyed your code exacle as it is but when i debac it says "This webpage is not available" on a browser. What myt be the problem
m.asghari 20-Jul-13 7:33am
   
why do not play .dat files???
ketan italiya 26-Nov-13 3:13am
   
superb code,it's working nice,thanks.......
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

<div>
        <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
            DataSourceID="SqlDataSource1" BackColor="#CCCCCC" BorderColor="#999999" 
            BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" 
            ForeColor="Black">
            <columns>
                <asp:templatefield headertext="Welcome Here are few Uploads Done by you!!">
                    <itemtemplate>
                        <asp:hyperlink id="HyperLink1" runat="server">
                            NavigateUrl='<%# Eval("id", "~/Default5.aspx?id={0}") %>' 
                            Text='<%# "Click Here to Play Video"+ Eval("id") %>' ondatabinding="HyperLink1_DataBinding"></asp:hyperlink>
                    </itemtemplate>
                </asp:templatefield>
            </columns>
            <footerstyle backcolor="#CCCCCC" />
            <headerstyle backcolor="Black" font-bold="True" forecolor="White" />
            <pagerstyle backcolor="#CCCCCC" forecolor="Black" horizontalalign="Left" />
            <rowstyle backcolor="White" />
            <selectedrowstyle backcolor="#000099" font-bold="True" forecolor="White" />
            <sortedascendingcellstyle backcolor="#F1F1F1" />
            <sortedascendingheaderstyle backcolor="#808080" />
            <sorteddescendingcellstyle backcolor="#CAC9C9" />
            <sorteddescendingheaderstyle backcolor="#383838" />
        </asp:gridview>
        <asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
            ConnectionString="<%$ ConnectionStrings:examConnectionString %>" 
            SelectCommand="SELECT * FROM [video]"></asp:sqldatasource>
    </div>
    <div>
        <asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
        <itemtemplate>
         <object id="MediaPlayer" width="270" height="270">
            CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"  STANDBY="Loading Windows Media Player components..."
            TYPE="application/x-oleobject"><param name="autoplay" value="true">
            <param name="width" value="270">
            <param name="height" value="270">
            <param name="FileName" value="<%#">></param></param></param></param></object>
        </itemtemplate>
        </asp:repeater>
    </div>



Code Behind Will be:

private void bindrepeater()
    {
       
        if (string.IsNullOrEmpty(Request.QueryString["id"]))
        {
           //do nothing
        }
        else
        {
            SqlCommand cmd = new SqlCommand("select name from video where id=@id", con);
            cmd.Parameters.AddWithValue("@id", Request.QueryString["id"]);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
 
            da.Fill(ds);
            Repeater1.DataSource = ds;
            Repeater1.DataBind();
        }
    }
    public string grtdata()
    {
        SqlCommand cmd = new SqlCommand("select name from video", con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
 

        string filename = dr[0].ToString();
        string path = "~/Videos/";//Name of folder where you will save your videos
        string opath = Server.MapPath(path);
 
        dr.Close();
        con.Close();
        return opath;
    }
    protected void HyperLink1_DataBinding(object sender, EventArgs e)
    {
        bindrepeater();
    }


[edit]code block added[/edit]
  Permalink  
v2

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100