我在网上找了一些代码,根据自己的需要现在写了这个类,现在发出来,希望能帮助大家.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;
/// <summary>
/// video 的摘要说明
/// </summary>
public class video
{
public video()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 弹出播放器
/// </summary>
/// <param name="sql"></param>
/// <param name="conn"></param>
public static void videoi(string sql,SqlConnection conn)
{
StreamWriter srd = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("Video/list.m3u"), false, System.Text.Encoding.GetEncoding("gb2312"));
srd.Write("http://" + HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"] + "/Video/" + filmName(sql, conn) + "/n/r");
srd.Close();
}
public static string filmName(string sql,SqlConnection conn)
{
conn.Open();
SqlCommand scd = new SqlCommand(sql, conn);
string strFilmPath = Convert.ToString(scd.ExecuteScalar());
conn.Close();
return strFilmPath;
}
/// <summary>
/// 下载代码
/// </summary>
/// <param name="sql"></param>
/// <param name="conn"></param>
public static void down(string sql,SqlConnection conn)
{
string name =filmName(sql,conn);
string filename = "Video/" + name;
if (filename != "")
{
string path = System.Web.HttpContext.Current.Server.MapPath(filename);
FileInfo file = new FileInfo(path);
if (file.Exists)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpContext.Current.Server.UrlEncode(name));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream; charset=gb2312";
HttpContext.Current.Response.Filter.Close();
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.End();
}
}
}
/// <summary>
/// 在网页上的播放器
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="url"></param>
public static void webVideo(int width,int height,string url)
{
HttpContext.Current.Response.Write("<OBJECT id='WindowsMediaPlayer1' style='WIDTH:" +width+"; HEIGHT: "+height+"' classid='clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6'>");
HttpContext.Current.Response.Write("<PARAM NAME='URL' VALUE='"+url+"'>");
HttpContext.Current.Response.Write("<PARAM NAME='rate' VALUE='1'>");
HttpContext.Current.Response.Write("<PARAM NAME='balance' VALUE='0'>");
HttpContext.Current.Response.Write("<PARAM NAME='defaultFrame' VALUE=''>");
HttpContext.Current.Response.Write("<PARAM NAME='playCount' VALUE='1'>");
HttpContext.Current.Response.Write("<PARAM NAME='autoStart' VALUE='-1'>");
HttpContext.Current.Response.Write("<PARAM NAME='currentMarker' VALUE='0'>");
HttpContext.Current.Response.Write("<PARAM NAME='invokeURLs' VALUE='-1'>");
HttpContext.Current.Response.Write("<PARAM NAME='baseURL' VALUE=''>");
HttpContext.Current.Response.Write("<PARAM NAME='volume' VALUE='50'>");
HttpContext.Current.Response.Write("<PARAM NAME='mute' VALUE='0'>");
HttpContext.Current.Response.Write("<PARAM NAME='uiMode' VALUE='full'>");
HttpContext.Current.Response.Write("<PARAM NAME='stretchToFit' VALUE='0'>");
HttpContext.Current.Response.Write("<PARAM NAME='windowlessVideo' VALUE='0'>");
HttpContext.Current.Response.Write("<PARAM NAME='enabled' VALUE='-1'>");
HttpContext.Current.Response.Write("<PARAM NAME='enableContextMenu' VALUE='-1'>");
HttpContext.Current.Response.Write("<PARAM NAME='fullScreen' VALUE='0'>");
HttpContext.Current.Response.Write("<PARAM NAME='SAMIStyle' VALUE=''>");
HttpContext.Current.Response.Write("<PARAM NAME='SAMILang' VALUE=''>");
HttpContext.Current.Response.Write("<PARAM NAME='SAMIFilename' VALUE=''>");
HttpContext.Current.Response.Write("<PARAM NAME='captioningID' VALUE=''>");
HttpContext.Current.Response.Write("<PARAM NAME='enableErrorDialogs' VALUE='0'>");
HttpContext.Current.Response.Write("<PARAM NAME='_cx' VALUE='11113'>");
HttpContext.Current.Response.Write("<PARAM NAME='_cy' VALUE='7461'>");
HttpContext.Current.Response.Write("</OBJECT>");
}
}