如何添加对视频流的顺序访问?

我正在使用下面的代码从我的SQL Server中播放.flv视频。但据我所知,整个视频将在播放前加载到内存中。我想要做的是将CommandBehavior.SequentialAccess添加到SQLDataReader ......但我无法让它工作。 请帮帮我。如果你能提供一个适用于我的工作实例,我会很高兴。 Psuedo代码将是第二个最佳选择。任何指针都很受欢迎。 这是我的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; }
    }
}
    
已邀请:
第一:不要从数据库流。 第二:如果你真的想从数据库中流式传输,下面就是你如何做到这一点的例子。但不要。真。将指针(文件路径)存储在数据库中,并将流处理留给ISS或您使用的任何服务器。     

要回复问题请先登录注册