以下のコードを使用して、SQL Server から .flv ビデオをストリーミングしています。しかし、私が理解していることから、ビデオ全体が再生される前にメモリにロードされます。CommandBehavior.SequentialAccess を SQLDataReader に追加したいのですが、うまくいきません。
ここで私を助けてください。私に当てはまる実用的な例を提供できれば幸いです。疑似コードは、2 番目に優れた代替手段です。ただし、任意のポインタをいただければ幸いです。
これが私のhttpHandlerです
public class ViewFilm : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
try
{
// Check if video id was given
if (context.Request.QueryString["id"] != null)
{
string video_ID = context.Request.QueryString["id"];
// Connect to DB and get the video
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
using (SqlCommand cmd = new SqlCommand("GetVideo", con))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter sqlParam = cmd.Parameters.Add("@videoId", SqlDbType.Int);
sqlParam.Value = video_ID;
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.HasRows)
{
dr.Read();
// Add HTTP header: cache, content type and length
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(DateTime.Now);
context.Response.AppendHeader("Content-Type", "video/x-flv");
context.Response.AppendHeader("Content-Length", ((byte[])dr["data"]).Length.ToString());
context.Response.BinaryWrite((byte[])dr["data"]);
}
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
public bool IsReusable
{
get { return false; }
}
}