Asp.net mvc WMV电影未在Windows Media Player的MVC视图中显示
我无法使嵌入式windows media player在MVC视图中工作:Asp.net mvc WMV电影未在Windows Media Player的MVC视图中显示,asp.net-mvc,wmv,Asp.net Mvc,Wmv,我无法使嵌入式windows media player在MVC视图中工作: <div id="divCourseVideo" style="width:80%;margin:0 auto" class="container"> <OBJECT ID="CoursePlayer" HEIGHT="400" WIDTH="400" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="video/x-ms-w
<div id="divCourseVideo" style="width:80%;margin:0 auto" class="container">
<OBJECT ID="CoursePlayer" HEIGHT="400" WIDTH="400" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="video/x-ms-wmv">
<param name='URL' value="~/App_Data/orangeblossom.wmv" />
<param name='SendPlayStateChangeEvents' value='true' />
<param name='uiMode' value='full' />
<param name='AutoStart' value="false" />
<param name='showControls' value="true" />
<param name='loop' value="false" />
<param name="allowfullscreen" value="false" />
</OBJECT>
</div>
这也不起作用:
<embed type="application/x-mplayer2" width="300" height="300" src="~/App_Data/orangeblossom.wmv" showstatusbar="1" />
首先在项目中创建类
using System.IO;
using System.Web.Hosting;
using System.Web.Mvc;
namespace MVC_CustomActionResult.CustomResult
{
public class VideoResult : ActionResult
{
/// <summary>
/// The below method will respond with the Video file
/// </summary>
/// <param name="context"></param>
public override void ExecuteResult(ControllerContext context)
{
//The File Path
var videoFilePath =HostingEnvironment.MapPath("~/VideoFile/Win8.mp4");
//The header information
context.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=Win8.mp4");
var file = new FileInfo(videoFilePath);
//Check the file exist, it will be written into the response
if (file.Exists)
{
var stream = file.OpenRead();
var bytesinfile = new byte[stream.Length];
stream.Read(bytesinfile, 0, (int)file.Length);
context.HttpContext.Response.BinaryWrite(bytesinfile);
}
}
}
}
运行应用程序并导航到、视频/索引URL和下载体验
using MVC_CustomActionResult.CustomResult;
using System.Web.Mvc;
namespace MVC_CustomActionResult.Controllers
{
public class VideoController : Controller
{
//
// GET: /Video/
public ActionResult Index()
{
return new VideoResult();
}
}
}
从上述操作方法添加新视图,并在其中添加以下HTML 5视频标记:
<video width="320" height="240" controls autoplay="autoplay">
<source src="@Url.Action("Index","Video")" type="video/mp4">
< /video>
有关更多说明,请访问
Mahesh Sabnis解释如下更改代码:
<div id="divCourseVideo" style="width:80%;margin:0 auto" class="container">
<OBJECT ID="CoursePlayer" HEIGHT="400" WIDTH="400" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="video/x-ms-wmv">
<param name='URL' value="@Url.Content("~/App_Data/orangeblossom.wmv")" />
<param name='SendPlayStateChangeEvents' value='true' />
<param name='uiMode' value='full' />
<param name='AutoStart' value="false" />
<param name='showControls' value="true" />
<param name='loop' value="false" />
<param name="allowfullscreen" value="false" />
<embed type="application/x-mplayer2" width="300" height="300" pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/' src="@Url.Content("~/App_Data/orangeblossom.wmv")" showstatusbar="1" />
</OBJECT>
当我使用IE调试时,我看到它试图将文件作为“文本”文件拉入。mime类型是在applicationhost.config文件中定义的,所以我不明白为什么会发生这种情况!
<div id="divCourseVideo" style="width:80%;margin:0 auto" class="container">
<OBJECT ID="CoursePlayer" HEIGHT="400" WIDTH="400" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="video/x-ms-wmv">
<param name='URL' value="@Url.Content("~/App_Data/orangeblossom.wmv")" />
<param name='SendPlayStateChangeEvents' value='true' />
<param name='uiMode' value='full' />
<param name='AutoStart' value="false" />
<param name='showControls' value="true" />
<param name='loop' value="false" />
<param name="allowfullscreen" value="false" />
<embed type="application/x-mplayer2" width="300" height="300" pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/' src="@Url.Content("~/App_Data/orangeblossom.wmv")" showstatusbar="1" />
</OBJECT>