Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems that JW Player figures out the kind of file to play based on the file extension in the <code>file</code> option. Because you are streaming these from disk, via an ASPX page, you don't have one.</p> <p>The following is how I got this working with JW Player 6 (using mp3s - I didn't have any mp4s handy):</p> <pre><code>jwplayer("player1").setup({ flashplayer: "/jwplayer/jwplayer.flash.swf", file: '/Streamer.ashx', height: 340, width: 388, type: 'mp3' }); </code></pre> <p>The key was the use of <code>type</code> to indicate what kind of file was on the other end. The only reference I can offer for this is <a href="http://www.longtailvideo.com/support/forums/jw-player/setup-issues-and-embedding/74/php-http-streaming" rel="nofollow noreferrer">here</a>: it dates back to 2007, but I couldn't seem to find mentions of <code>type</code> in the documention.</p> <p>Inspired by: <a href="https://stackoverflow.com/questions/4399728/how-do-i-stream-flv-files-from-sql-database">How do I stream .flv files from SQL database</a>, I implemeted an HTTP handler to do the streaming:</p> <pre><code>public class Streamer : IHttpHandler { public void ProcessRequest(HttpContext context) { string filePath = "my file path"; byte[] buffer = File.ReadAllBytes(filePath); context.Response.Clear(); context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetLastModified(DateTime.Now); context.Response.AppendHeader("Content-Type", "audio/mpeg3"); context.Response.AddHeader("Content-Disposition", "attachment;filename=file.mp3"); context.Response.AppendHeader("Content-Length", buffer.Length.ToString()); context.Response.BinaryWrite(buffer); } public bool IsReusable { get { return false; } } } </code></pre> <p>Note that an ASPX page would probably work fine as well, though handlers are more appropriate for this kind of task (and should be more efficient as they don't have a page cycle).</p> <p>Reading the whole file into memory isn't ideal, but it sufficed for proving the concept.</p>
 

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