asp.net – 如何从SQL数据库流.flv文件

前端之家收集整理的这篇文章主要介绍了asp.net – 如何从SQL数据库流.flv文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将.flv文件存储在数据库中,而不是在文件系统中.

这是我现在可以做的:
使用ffmpeg成功将.wmv和.mpeg转换为.flv.
将图像存储在sql Server中,并使用httphandler将其显示在我的页面上.
与.avi和.mpeg视频一样. (由用户的软件,如果他可以查看它)
如果文件位于文件系统中而不在数据库中,则在浏览器中播放.flv文件.

我不能做的是:
将.flv视频直接从数据库传输到JW Player. (存储为二进制数据)

我已经在互联网上搜索了两天,但我不能让它上班.感觉好像我几乎在那里. JW播放器打开并开始“缓冲”,但没有任何反应.

我知道没有简单的答案,但是如果有人以前做过或类似的事情,我想知道你是怎么做到的.我觉得我有太多的代码在这里发布.

提前致谢!

解决方法

我得到它的工作,但我不知道如何有效率.从连接,效率,负载等方面来看,从文件系统流出的最好是从数据库.
我可以用一些指针就可以了!

我在这里使用JW Player,因此“swfobject.js”和“player.swf”

HttpHandler的:

  1. public class ViewFilm : IHttpHandler
  2. {
  3. public void ProcessRequest(HttpContext context)
  4. {
  5. try
  6. {
  7. // Check if id was given
  8. if (context.Request.QueryString["id"] != null)
  9. {
  10. string movId = context.Request.QueryString["id"];
  11.  
  12. // Connect to DB and get the item id
  13. using (sqlConnection con = new sqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
  14. using (sqlCommand cmd = new sqlCommand("GetItem",con))
  15. {
  16. cmd.CommandType = CommandType.StoredProcedure;
  17. sqlParameter sqlParam = cmd.Parameters.Add("@itemId",sqlDbType.Int);
  18. sqlParam.Value = movId;
  19.  
  20. con.Open();
  21. using (sqlDataReader dr = cmd.ExecuteReader())
  22. {
  23. if (dr.HasRows)
  24. {
  25. dr.Read();
  26. // Add HTTP header stuff: cache,content type and length
  27. context.Response.Cache.SetCacheability(HttpCacheability.Public);
  28. context.Response.Cache.SetLastModified(DateTime.Now);
  29. context.Response.AppendHeader("Content-Type","video/x-flv");
  30. context.Response.AppendHeader("Content-Length",((byte[])dr["data"]).Length.ToString());
  31. context.Response.BinaryWrite((byte[])dr["data"]);
  32. }
  33. }
  34. }
  35. }
  36. }
  37. catch (Exception ex)
  38. {
  39. throw new Exception(ex.ToString());
  40. }
  41. }
  42.  
  43. public bool IsReusable
  44. {
  45. get { return false; }
  46. }
  47. }

JavaScript的
功能将播放器添加到< div id =“video1”>并且可以称为例如当用户单击按钮时.

  1. <script type='text/javascript' src='swfobject.js'></script>
  2. <script type="text/javascript" language="javascript">
  3. function vid() {
  4. var s1 = new SWFObject('player.swf','player1','480','270','9');
  5. s1.addParam('allowfullscreen','true');
  6. s1.addParam('allowscriptaccess','always');
  7. s1.addVariable('file',encodeURIComponent('ViewFilm.ashx?id=10'));
  8. s1.addVariable('type','video');
  9. s1.write(document.getElementById("video1"));
  10. }
  11. </script>

猜你在找的asp.Net相关文章