Windows Media Player 的 MVC 视图中未显示 WMV 电影
WMV movie not showing in MVC view of Windows Media Player
我无法让嵌入式 windows 媒体播放器在 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-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" />
先在你的项目中创建一个class
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);
}
}
}
}
在应用中,添加一个新的MVC Empty Controller,命名为VideoController,实现如下代码
using MVC_CustomActionResult.CustomResult; //Here your class name which you create in you sollution
using System.Web.Mvc;
namespace MVC_CustomActionResult.Controllers
{
public class VideoController : Controller
{
//
// GET: /Video/
public ActionResult Index()
{
return new VideoResult();
}
}
}
运行 应用程序并导航到 Video/Index 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();
}
}
}
从上面的action方法中添加一个新的View,并在里面添加如下HTML5个Video标签:
<video width="320" height="240" controls autoplay="autoplay">
<source src="@Url.Action("Index","Video")" type="video/mp4">
< /video>
有关更多说明,请访问
http://www.dotnetcurry.com/aspnet-mvc/998/play-videos-aspnet-mvc-custom-action-filter,very 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>
我无法让嵌入式 windows 媒体播放器在 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-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" />
先在你的项目中创建一个class
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);
}
}
}
}
在应用中,添加一个新的MVC Empty Controller,命名为VideoController,实现如下代码
using MVC_CustomActionResult.CustomResult; //Here your class name which you create in you sollution
using System.Web.Mvc;
namespace MVC_CustomActionResult.Controllers
{
public class VideoController : Controller
{
//
// GET: /Video/
public ActionResult Index()
{
return new VideoResult();
}
}
}
运行 应用程序并导航到 Video/Index 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();
}
}
}
从上面的action方法中添加一个新的View,并在里面添加如下HTML5个Video标签:
<video width="320" height="240" controls autoplay="autoplay">
<source src="@Url.Action("Index","Video")" type="video/mp4">
< /video>
有关更多说明,请访问 http://www.dotnetcurry.com/aspnet-mvc/998/play-videos-aspnet-mvc-custom-action-filter,very 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>