1
我試圖檢索存儲在SQL Server數據庫中的FLV視頻並使用JWplayer插件顯示它。 當我跑我得到這個錯誤:ASP.NET MVC:從SQL Server視頻流
任務隊列未能在第5步中的播放列表文件不包含一個有效的 播放列表
我的代碼:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult GetVideo(int id)
{
byte[] contents =_contentAssestTask.GetItem(id).FileContent;
var ms = new MemoryStream();
ms.Write(contents, 0, contents.Length);
ms.Position = 0;
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetLastModified(DateTime.Now);
Response.AppendHeader("Content-Type", "video/x-flv");
Response.AppendHeader("Content-Length", contents.Length.ToString());
return new FileStreamResult(ms, "video/x-flv");
}
和視圖包含:
<script type="text/javascript" src="@Url.Content("~/Scripts/jwplayer.js")"> </script>
<div id='mediaplayer'></div>
<script type="text/javascript">
jwplayer('mediaplayer').setup({
'flashplayer': '@Url.Content("~/Content/Video/player.swf")',
'id': 'playerID',
'width': '480',
'height': '270',
'file': '@Url.Action("GetVideo","MultiMedia",new {id=2})',
'image': '',
'plugins': {
'viral-2': {
'onpause': 'false',
'callout': 'none'
}
}
});
</script>
爲什麼不使用'FileContentResult'而不是'FileStreamResult'?這可以讓你避免將緩衝區寫入流中。另外,使用'FileContent'方法而不是'FileContentResult'類。 –