您的位置:首页 > 其它

请问如何动态实现播放语音文件[WEB学习示例]

2009-08-07 19:01 615 查看
重新发布完整代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 多媒体播放 : System.Web.UI.Page
{
    DateTime Date = System.DateTime.Now;
    TiShi_XinXi Ts_XinXi = new TiShi_XinXi();
    ShuJuKu_ChaoZuo SJK_CaoZuo = new ShuJuKu_ChaoZuo();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Label2.Text = PlayMedia("Gong_Ju/《南無观世音菩萨》.WMV");
        }

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

前台网页:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="多媒体播放.aspx.cs" Inherits="多媒体播放" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .TD
        {width: 20%;}
        .denglu-td
        {
        }
        </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table class="style2">
        <tr>
            <td>
                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                 </td>
        </tr>
    </table>
</asp:Content>




看看另一个播放器,播放网络视频:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 多媒体播放 : System.Web.UI.Page
{
    DateTime Date = System.DateTime.Now;
    TiShi_XinXi Ts_XinXi = new TiShi_XinXi();
    ShuJuKu_ChaoZuo SJK_CaoZuo = new ShuJuKu_ChaoZuo();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Label2.Text = 网络视频文件("http%3A%2F%2Fwww%2Egdd%2Ero%2Fflvplayer%2Fexamples%2Fvideo%2Emp4&splashscreen=http://www.gdd.ro/flvplayer/examples/fast-and-furious-1.jpg");
        }

    }
    public string 网络视频文件(string MediaFile)
    {
        string strScript = "";
        strScript += "<TABLE id=\"Table2\" align=\"center\" border=\"0\" runat=\"server\" width = '620' height ='450'>";
        strScript += "<TR>";
        strScript += "<TD align=\"center\">";
        strScript += "<embed src=\"http://www.gdd.ro/gdd/flvplayer/gddflvplayer.swf\"";
        strScript += "flashvars=\"?&autoplay=true&sound=70&buffer=2&";
        strScript += "vdo=" + MediaFile + "\""; /*网络视频地址*/
        strScript += "width = \"468\"";
        strScript += "height=\"328\"";
        strScript += "allowFullScreen=\"true\"";
        strScript += "quality=\"best\"";
        strScript += "wmode=\"transparent\"";
        strScript += "allowScriptAccess=\"always\"";
        strScript += "pluginspage=\"http://www.macromedia.com/go/getflashplayer\"";
        strScript += "type = \"application/x-shockwave-flash\" >";
        strScript += "</embed>";
        strScript += "</TD>";
        strScript += "</TR>";
        strScript += "</TABLE>";
        return strScript;
    }
}



来自点击打开链接 中的生成器生成的代码写成以上播放器代码,一时找不到合适的网络视频文件地址,地址直接写在里面了,可以自己替换有注释的语句.
播放本地视频文件测试把文件放在一个文件夹中,这里示例为网站工程文件夹

Gong_Ju中放一个文件:美女广告.flv,把 http://localhost:1463/GuanLan_ZiYuan/Gong_Ju/美女广告.flv
这个地址用生成器生成复制地址作传递参数:Label2.Text = 网络视频文件("http%3A%2F%2Flocalhost%3A1463%2FGuanLan%5FZiYuan%2FGong%5FJu%2F%E7%BE%8E%E5%A5%B3%E5%B9%BF%E5%91%8A%2Eflv");就可以播放本地文件了.
Label2.Text = 网络视频文件(System.Uri.EscapeDataString("http://localhost:1463/GuanLan_ZiYuan/Gong_Ju/美女广告.flv"));





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐