Nik*_*las 12 sql asp.net jwplayer streaming-flv-video
我想将.flv文件存储在数据库中,而不是存储在文件系统中.
这就是我现在能做的:
用ffmpeg成功地将.wmv和.mpeg转换为.flv.
将图像存储在SQL Server中,并使用httphandler在我的页面上显示它们.
与.avi和.mpeg视频相同.(这取决于用户的软件,如果他可以查看它)
如果文件位于文件系统而不是数据库中,则在浏览器中播放.flv文件.
我不能做的是:
直接从数据库中将.flv视频流传输到JW Player.(存储为二进制数据)
我已经在互联网上搜索了两天,但我无法让它工作.感觉好像我几乎在那里.JW Player打开并开始"缓冲",但没有任何反应.
我知道没有简单的答案,但如果有人之前做过这个,或类似的事情,我想知道你是怎么做的.我觉得我有太多的代码要在这里发布.
提前致谢!
我让它工作了,但我不知道它的效率如何。就连接、效率、负载等而言,从文件系统进行流式传输比从数据库进行流式传输更好吗?我可以在这方面使用一些指针!
我在这里使用 JW Player,因此为“swfobject.js”和“player.swf”
http处理程序:
public class ViewFilm : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
try
{
// Check if id was given
if (context.Request.QueryString["id"] != null)
{
string movId = context.Request.QueryString["id"];
// Connect to DB and get the item id
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
using (SqlCommand cmd = new SqlCommand("GetItem", con))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter sqlParam = cmd.Parameters.Add("@itemId", SqlDbType.Int);
sqlParam.Value = movId;
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.HasRows)
{
dr.Read();
// Add HTTP header stuff: 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; }
}
}
Run Code Online (Sandbox Code Playgroud)
javascript
该函数添加一个播放器,<div id="video1">并且可以在用户单击按钮时调用。
<script type='text/javascript' src='swfobject.js'></script>
<script type="text/javascript" language="javascript">
function vid() {
var s1 = new SWFObject('player.swf', 'player1', '480', '270', '9');
s1.addParam('allowfullscreen', 'true');
s1.addParam('allowscriptaccess', 'always');
s1.addVariable('file', encodeURIComponent('ViewFilm.ashx?id=10'));
s1.addVariable('type', 'video');
s1.write(document.getElementById("video1"));
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4524 次 |
| 最近记录: |