在ASP.NET中播放视频

时间:2016-01-04 12:40:34

标签: asp.net flash

我正在尝试在我的网站上嵌入Flash播放器。但由于某种原因,文件没有播放。我无法看到视频播放器。以下是我的代码

_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>");

有关如何启用Flash播放器播放.swf,.flv,.mov视频的任何帮助?

编辑:Youtube下面的代码正常

    _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();

1 个答案:

答案 0 :(得分:1)

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的显示/隐藏课程功能

  

浏览器必须安装插件才能使其正常工作。

根据here的文件说明

  

您无法直接显示Flash视频文件。 Flash只是一个编程框架,它使用Action Script编程语言。您需要使用Flash(视频播放器)制作的程序在页面上显示.flv视频。

所以这里的基本代码是

<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>

如需完整参考,请找到以下链接: -

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

更新播放.swf视频代码

创建和播放 swf 文件非常简单。

  1. 打开Microsoft Visual Studio。创建一个网站并将其命名为PlaySwfFile

  2. 创建.aspx文件并将其命名为PlaySwfFile.aspx

  3. 设计看起来像这样的表单。

  4. enter image description here

    1. 或者将代码复制并粘贴到PlaySwfFile.aspx标记
    2. 内的<body>文件中

      <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. 现在将名称空间System.IO;添加到PlaySwfFile.aspx.cs文件

      2. 在page_load()方法

        之上声明一个变量
        public string swfFileName = "";
        
      3. Upload button的代码位于

      4. 之下

        按钮代码: -

        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;
            }
        }
        

        检查上传的文件是否为swf

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

        这是上传Flash视频并在浏览器上播放的完整代码。

        希望有所帮助