我試圖通過ashx頁面將flv文件加載到JWPlayer中。但我總是得到以下錯誤:JW Player無法顯示通過文件處理程序(.ashx)提供的flv
Task Queue failed at step 5: Playlist could not be loaded: Playlist file did not contain a valid playlist
如果我直接在Firefox中加載ashx頁面,視頻將加載並自動播放。如果我改變flvplayer直接指向一個flv文件,它工作正常。所以我對這個問題有些困惑!我注意到的一件事是,直接通過瀏覽器播放時,ashx頁面後面的代碼運行兩次,第二次沒有會話變量可用,儘管Fiddler只能檢測到瀏覽器的一個請求。當JWPlayer調用ashx頁面時,代碼只執行一次。
任何幫助,將不勝感激!
<%@ WebHandler Language="C#" Class="CourseVideoHandler" %>
using System;
using System.Web;
using System.Web.SessionState;
using System.IO;
public class CourseVideoHandler : IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "video/x-flv";
FileStream fs = File.Open(HttpContext.Current.Server.MapPath("~/content/coursevideos/rowthe boat.flv"),
FileMode.Open);
byte[] b = new byte[fs.Length];
fs.Read(b, 0, (int) fs.Length);
fs.Close();
context.Response.OutputStream.Write(b, 0, b.Length);
}
public bool IsReusable {
get {
return false;
}
}
}
<!-- START OF THE PLAYER EMBEDDING TO COPY-PASTE -->
<div id="mediaplayer">JW Player goes here</div>
<script type="text/javascript" src="jwplayer.js"></script>
<script type="text/javascript">
jwplayer("mediaplayer").setup({
flashplayer: "player.swf",
file: "../../CourseVideoHandler.ashx?t=.flv",
image: "preview.jpg"
});
</script>
<!-- END OF THE PLAYER EMBEDDING -->