Richa
Richa

Reputation: 3289

Play video in ASP.NET

I am trying to embed flash player on my web site. But for some reason the files are not playing. I am not able to see video player. Below is my code

_uri = Filepath + filename;  //--local Video

sb.Append("<object type='application/x-shockwave-flash' width='315px' height='230px' data='flvplayer_v5.6.swf?file=" + _uri + "&amp;autostart=false'>");
sb.Append("<param name='movie' value='flvplayer_v5.6.swf?file=" + _uri + "&amp;autostart=false'>");
sb.Append("<param name='allowfullscreen' value='true'><a href='http://www.macromedia.com/go/getflashplayer'></a></object>");

Any help on how to enable flash player to play .swf , .flv , .mov videos?

Edit : Below code for Youtube works fine

    _uri = filename;
sb.Append("<iframe frameborder='0' width='315px' height='230px' src='" + _uri + "' allowfullscreen>");
sb.Append("</iframe>");
sb.Append("<br /><a href='" + externalurl + "'  target='_blank'></a>");
                    dvMyHtml.InnerHtml = sb.ToString();

Upvotes: 1

Views: 1074

Answers (1)

HEEN
HEEN

Reputation: 4721

As discussed, the main issue seems to me is of flash which is stopping the videos to be played other than youtube videos.

So the first thing comes to me from here is

browser must have plug-in installed in order make this work.

As per documentation from here It states that

You can't show flash video files directly. Flash is just a programming framework, which uses Action Script programming language. You need a program made in Flash (video player) to show .flv video on page.

So the basic code for that here is

<td align="left" 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"
        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>
    </object>
</td>

For full reference find the link below:-

http://www.codeproject.com/Articles/30512/How-To-Play-SWF-File-In-Asp-Net

UPDATED (Code for playing .swf videos)

It is very simple to create and to play swf file.

  1. Open Microsoft Visual Studio. Create a web site and named it PlaySwfFile.

  2. Create an .aspx file and named it PlaySwfFile.aspx.

  3. Design the form that looks like this.

enter image description here

  1. Or copy and paste the code in PlaySwfFile.aspx file inside the <body> tag

<form id="form1" runat="server">
        <table width="410px">
            <tr>
                <td align="center"  valign="top">
                    <table border="0" cellpadding="2" cellspacing="3" style="width: 400px;">
                        <tr>
                            <td valign="top" style="width: 150px">
                            </td>
                            <td align="left" valign="top" style="width: 200px">
                                <asp:Label ID="lblMsg" CssClass="tdMessage"  Text ="" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td valign="top" class="tdText" align="left">
                              <nobr> Select a file</nobr> </td>
                            <td valign="top" style="text-align: left">
                                <asp:FileUpload ID="fUpload" runat="server" Width="300px" /></td>
                        </tr>
                        <tr>
                            <td align="left" valign="top">
                                <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" /></td>
                            <td align="left" 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"
                                    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>
                                </object>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>

  1. Now Add a namespace System.IO; to the PlaySwfFile.aspx.cs file

  2. Declare a variable above page_load() method

    public string swfFileName = "";
    
  3. And the code for Upload button is below

Button code:-

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 = "image/" + fUpload.PostedFile.FileName;
    }
}

Checking whether uploaded file is swf or not

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 + "image\\";
}

This is the full code for uploading flash videos and playing it on the browser.

Hope that helps

Upvotes: 1

Related Questions