2011年12月6日 星期二

[ASP.net WebForm] 網頁播放影音語法 (含.flv檔)

要在網頁播放影音,最簡單做法就是嵌入Windows Media Player,語法如下
#region 網頁嵌入Windows Media Player影音
    /// <summary>
    /// 網頁嵌入Windows Media Player影音
    /// </summary>
    /// <param name="width">影音寬度,建議374</param>
    /// <param name="height">影音高度,建議355</param>
    /// <param name="httpFilePath">Http完整檔案路徑</param>
    /// <returns>回傳 影音的HTML程式碼</returns>
    public string MovieHtml(int width, int height, string httpFilePath)
    {
        string content_att = string.Empty;

        content_att += "<div align='center'>";
        content_att += "<OBJECT ID='ActiveMovie1' WIDTH='" + width + "' HEIGHT='"+height+"' CLASSID='CLSID:05589FA1-C356-11CE-BF01-00AA0055595A'>";
        content_att += "<PARAM NAME='Version' VALUE='1'>";
        content_att += "<PARAM NAME='EnableContextMenu' VALUE='-1'>";
        content_att += "<PARAM NAME='ShowDisplay' VALUE='0'>";
        content_att += "<PARAM NAME='ShowControls' VALUE='-1'>";
        content_att += "<PARAM NAME='ShowPositionControls' VALUE='0'>";
        content_att += "<PARAM NAME='ShowSelectionControls' VALUE='0'>";
        content_att += "<PARAM NAME='EnablePositionControls' VALUE='-1'>";
        content_att += "<PARAM NAME='EnableSelectionControls' VALUE='-1'>";
        content_att += "<PARAM NAME='ShowTracker' VALUE='-1'>";
        content_att += "<PARAM NAME='EnableTracker' VALUE='-1'>";
        content_att += "<PARAM NAME='AllowHideDisplay' VALUE='-1'>";
        content_att += "<PARAM NAME='AllowHideControls' VALUE='-1'>";
        content_att += "<PARAM NAME='MovieWindowSize' VALUE='0'>";
        content_att += "<PARAM NAME='FullScreenMode' VALUE='0'>";
        content_att += "<PARAM NAME='AutoStart' VALUE='0'>";
        content_att += "<PARAM NAME='AutoRewind' VALUE='1'>";
        content_att += "<PARAM NAME='PlayCount' VALUE='99'>";
        content_att += "<PARAM NAME='SelectionStart' VALUE='0'>";
        content_att += "<PARAM NAME='SelectionEnd' VALUE='200.5151388'>";
        content_att += "<PARAM NAME='Appearance' VALUE='1'>";
        content_att += "<PARAM NAME='BorderStyle' VALUE='1'>";
        content_att += "<PARAM NAME='FileName' VALUE='" + httpFilePath + "'>";
        content_att += "<PARAM NAME='DisplayMode' VALUE='0'>";
        content_att += "<PARAM NAME='AllowChangeDisplayMode' VALUE='-1'>";
        content_att += "<PARAM NAME='DisplayForeColor' VALUE='16777215'>";
        content_att += "<PARAM NAME='DisplayBackColor' VALUE='0'>";
        content_att += "影音內容";
        content_att += "</OBJECT>";
        content_att += "</div>";


        return content_att;
    }

    #endregion


客戶想要在網頁上直接播放.flv檔(此需要透過第三方套件實現)

#region 網頁嵌入flv影音(網頁無法直接播放flv檔,開發時期,網站需要對外IP才能透過第三方播放flv)
//語法來源:http://bshadow.pixnet.net/blog/post/17173067
//網站架在IIS6的話,IIS6不認識flv副檔名,請見保哥設定:http://blog.miniasp.com/post/2008/12/03/Adding-Flash-video-FLV-MIME-Type-in-IIS.aspx
/// <summary>
/// 網頁嵌入flv影音(網頁無法直接播放flv檔,開發時期,網站需要對外IP才能透過第三方播放flv)
/// </summary>
/// <param name="width">影音寬度,建議374</param>
/// <param name="height">影音高度,建議355</param>
/// <param name="httpFilePath">Http完整檔案路徑</param>
/// <returns>回傳 flv的HTML程式碼</returns>
public string FlvHtml(int width, int height, string httpFilePath)
{
    string content_att = string.Empty;

     content_att =@"<object type='application/x-shockwave-flash' data='http://flv-player.net/medias/player_flv.swf' width='"+width+"' height='"+height+"'>"+
                    "<param name='movie' value='http://flv-player.net/medias/player_flv.swf' />"+
                    "<param name='allowFullScreen' value='true' />"+
                    "<param name='FlashVars' value='flv="+httpFilePath+"&width="+width+"&height="+height+"' />" +
                    //"<embed src='"+httpFilePath+"' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' wmode='transparent' width='"+width+"' height='"+height+"'></embed>" +
                    "<span style='display:none;'>flv影音檔</span>"+
                  "</object>";

    return content_att;
}

#endregion


原始文章出自於此

沒有留言:

張貼留言