在asp.net页面上实现媒体播放

原文及代码附件地址:http://www.dingos.cn/index.php?topic=628.0

【要求】能在asp.net页面上播放视频

【分析】在页面上播放视频实际上就是在通过“Windows Media Player”来播放视频。
【实现】在apsx页面上放一个Lable控件,这种方式可以写Javascript等控制页面,和布局页面。

【HTML页面】
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
     <TITLE>多媒体播放页面</TITLE>   
</head>
<body ms_positioning="GridLayout" bottomMargin=10 topMargin=10>
    <FORM id="Form1" method="post" runat="server">   
    <asp:Label id="lbl_MediaPlayer" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px"
     runat="server" Width="104px"></asp:Label>
  </FORM>
</body>
</html>
【.cs页面代码】
程序代码:
    protected void Page_Load(object sender, EventArgs e) {
        if(!this.IsPostBack) {
            string filename = "jbsong2.mpg";//要播放的媒体的名称 - 注意路径的正确写法
            this.lbl_MediaPlayer.Text = this.PlayMedia(filename);
        }
    }

    public string PlayMedia(string MediaFile) {
        string strScript =
         "<TABLE id=/"Table2/" align=/"center/" border=/"0/" runat=/"server/""
         + " width = '100%' height ='450'>"
         + "<TR>"
         + "<TD align=/"center/">"
         + "<OBJECT id=/"mdpTrailer/" classid=/"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95/""
         + " name=/"mdpTrailer/" width='620' height = '450'>"
         + "<PARAM NAME=/"AudioStream/" VALUE=/"-1/">"
         + "<PARAM NAME=/"AutoSize/" VALUE=/"-1/">"
         + "<PARAM NAME=/"AutoStart/" VALUE=/"-1/">"
         + "<PARAM NAME=/"AnimationAtStart/" VALUE=/"-1/">"
         + "<PARAM NAME=/"AllowScan/" VALUE=/"-1/">"
         + "<PARAM NAME=/"AllowChangeDisplaySize/" VALUE=/"-1/">"
         + "<PARAM NAME=/"AutoRewind/" VALUE=/"0/">"
         + "<PARAM NAME=/"Balance/" VALUE=/"0/">"
         + "<PARAM NAME=/"BaseURL/" VALUE=/"/">"
         + "<PARAM NAME=/"BufferingTime/" VALUE=/"5/">"
         + "<PARAM NAME=/"CaptioningID/" VALUE=/"/">"
         + "<PARAM NAME=/"ClickToPlay/" VALUE=/"-1/">"
         + "<PARAM NAME=/"CursorType/" VALUE=/"0/">"
         + "<PARAM NAME=/"CurrentPosition/" VALUE=/"-1/">"
         + "<PARAM NAME=/"CurrentMarker/" VALUE=/"0/">"
         + "<PARAM NAME=/"DefaultFrame/" VALUE=/"/">"
         + "<PARAM NAME=/"DisplayBackColor/" VALUE=/"0/">"
         + "<PARAM NAME=/"DisplayForeColor/" VALUE=/"16777215/">"
         + "<PARAM NAME=/"DisplayMode/" VALUE=/"0/">"
         + "<PARAM NAME=/"DisplaySize/" VALUE=/"4/">"
         + "<PARAM NAME=/"Enabled/" VALUE=/"-1/">"
         + "<PARAM NAME=/"EnableContextMenu/" VALUE=/"-1/">"
         + "<PARAM NAME=/"EnablePositionControls/" VALUE=/"-1/">"
         + "<PARAM NAME=/"EnableFullScreenControls/" VALUE=/"1/">"
         + "<PARAM NAME=/"EnableTracker/" VALUE=/"-1/">"
         + "<PARAM NAME=/"Filename/" VALUE=/"" + MediaFile + "/">"
         + "<PARAM NAME=/"InvokeURLs/" VALUE=/"-1/">"
         + "<PARAM NAME=/"Language/" VALUE=/"-1/">"
         + "<PARAM NAME=/"Mute/" VALUE=/"0/">"
         + "<PARAM NAME=/"PlayCount/" VALUE=/"1/">"
         + "<PARAM NAME=/"PreviewMode/" VALUE=/"0/">"
         + "<PARAM NAME=/"Rate/" VALUE=/"1/">"
         + "<PARAM NAME=/"SAMILang/" VALUE=/"/">"
         + "<PARAM NAME=/"SAMIStyle/" VALUE=/"/">"
         + "<PARAM NAME=/"SAMIFileName/" VALUE=/"/">"
         + "<PARAM NAME=/"SelectionStart/" VALUE=/"-1/">"
         + "<PARAM NAME=/"SelectionEnd/" VALUE=/"-1/">"
         + "<PARAM NAME=/"SendOpenStateChangeEvents/" VALUE=/"-1/">"
         + "<PARAM NAME=/"SendWarningEvents/" VALUE=/"-1/">"
         + "<PARAM NAME=/"SendErrorEvents/" VALUE=/"-1/">"
         + "<PARAM NAME=/"SendKeyboardEvents/" VALUE=/"0/">"
         + "<PARAM NAME=/"SendMouseClickEvents/" VALUE=/"0/">"
         + "<PARAM NAME=/"SendMouseMoveEvents/" VALUE=/"0/">"
         + "<PARAM NAME=/"SendPlayStateChangeEvents/" VALUE=/"-1/">"
         + "<PARAM NAME=/"ShowCaptioning/" VALUE=/"0/">"
         + "<PARAM NAME=/"ShowControls/" VALUE=/"-1/">"
         + "<PARAM NAME=/"ShowAudioControls/" VALUE=/"-1/">"
         + "<PARAM NAME=/"ShowDisplay/" VALUE=/"0/">"
         + "<PARAM NAME=/"ShowGotoBar/" VALUE=/"0/">"
         + "<PARAM NAME=/"ShowPositionControls/" VALUE=/"-1/">"
         + "<PARAM NAME=/"ShowStatusBar/" VALUE=/"0/">"
         + "<PARAM NAME=/"ShowTracker/" VALUE=/"-1/">"
         + "<PARAM NAME=/"TransparentAtStart/" VALUE=/"0/">"
         + "<PARAM NAME=/"VideoBorderWidth/" VALUE=/"0/">"
         + "<PARAM NAME=/"VideoBorderColor/" VALUE=/"0/">"
         + "<PARAM NAME=/"VideoBorder3D/" VALUE=/"0/">"
         + "<PARAM NAME=/"Volume/" VALUE=/"-600/">"
         + "<PARAM NAME=/"WindowlessVideo/" VALUE=/"0/">"
         + "</OBJECT>"
         + "</TD>"
         + "</TR>"
         + "</TABLE>";

        return strScript;
    }
【说明】
"<OBJECT id=/"mdpTrailer/" classid=/"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95/""
         + " name=/"mdpTrailer/" width='620' height = '450'>"

是为了加载 Windows Media Player控件。其中22D6F312-B0F6-11D0-94AB-0080C74C7E95是Windows Media Player在Windows系统中classid。

通过PARAM来设置Windows Media Player的各个属性,其中Name后面的是属性名,Value后面的是属性的值。
在vs2005下调试成功, 注意媒体的格式需要是Windows Media Player支持的格式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜晚回家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值