WMV电影未在Windows Media Player的MVC视图中显示

时间:2017-03-15 14:16:05

标签: asp.net-mvc wmv

我无法让嵌入式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" /> 

2 个答案:

答案 0 :(得分: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); 
        } 
    } 
} 
}

在应用程序中,添加一个新的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(); 
    }
   } 
  }

运行应用程序并导航到视频/索引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>

有关详细说明,请访问 http://www.dotnetcurry.com/aspnet-mvc/998/play-videos-aspnet-mvc-custom-action-filter,very由Mahesh Sabnis解释

答案 1 :(得分:0)

更改您的代码如下:

 <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>