Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I got it to work but I have no idea as to how efficient it is. Is it better to stream from the file system than from the database in terms of connections, efficency, load etc. I could use some pointers on this!</p> <p>I'm using JW Player here, hence "swfobject.js" and "player.swf"</p> <p><em>httpHandler:</em></p> <pre><code>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; } } } </code></pre> <p><em>javascript</em><br> The function adds a player to <code>&lt;div id="video1"&gt;</code> and can be called e.g when a user clicks a button. </p> <pre><code>&lt;script type='text/javascript' src='swfobject.js'&gt;&lt;/script&gt; &lt;script type="text/javascript" language="javascript"&gt; 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")); } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload