asp.net实现播放视频,利用Literal控件,将<object>网页多媒体标签从后台写入Literal控件中,实现视频的播放
项目文件夹Test/下准备好一个flv格式的播放器player.swf,
http://pan.baidu.com/share/link?shareid=1312514448&uk=1999820872
项目文件夹Test/下准备一个待播放的flv文件
http://pan.baidu.com/share/link?shareid=1315591318&uk=1999820872
PlayVideo.aspx
<div> <asp:Literal runat="server" ID="Literal1"> </asp:Literal> </div>
PlayVideo.aspx.cs
protected void Page_Load(object sender, EventArgs e) { string path = "Test/video.flv"; //视频路径 if (!path.StartsWith("http://")) //如果视频路径开头不是http:// { string absoPath = Request.Url.AbsoluteUri; //获取当前绝对路径 int position = absoPath.IndexOf("Test/PlayVideo.aspx");//查询PlayVideo.aspx在字符串中的位置 absoPath = absoPath.Substring(0, position);//截取字符串 path = absoPath + path; } path = "player.swf?fileName=" + path; string strHtml = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'" + " width='460' height='377' id='index' name='index'>" + "<param name='allowScriptAccess' value='always' />" + "<param name='movie' value='" +path + "'>" + "<embed src='" + path + "' id='index1' name='index1'" + " type='application/x-shockwave-flash' swLiveConnect=true" + " allowScriptAccess='always' width='480' height='395'></embed></object>"; //输出到Literal控件中,在网页中播放视频 this.Literal1.Text = strHtml; }