asp.net-mvcwmv

WMV movie not showing in MVC view of Windows Media Player


I cannot get the embedded windows media player to work in an MVC view:

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

Nor does this work:

 <embed type="application/x-mplayer2" width="300" height="300" src="~/App_Data/orangeblossom.wmv" showstatusbar="1" /> 

Solution

  • First to create a class in your project

    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); 
            } 
        } 
    } 
    }
    

    In the application, add a new MVC Empty Controller, name it as VideoController and implement the code as below

    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(); 
        }
       } 
      }
    

    Run the application and navigate to the, Video/Index URL and the download experience

    using MVC_CustomActionResult.CustomResult; 
    using System.Web.Mvc;
    namespace MVC_CustomActionResult.Controllers 
    { 
    public class VideoController : Controller 
    { 
        // 
        // GET: /Video/
        public ActionResult Index() 
        { 
            return new VideoResult(); 
        }
    } 
    }
    

    Add a new View from the above action method, and add the following HTML 5 Video tag in it:

    <video width="320" height="240" controls autoplay="autoplay"> 
    <source src="@Url.Action("Index","Video")" type="video/mp4"> 
    < /video>
    

    For more description visit http://www.dotnetcurry.com/aspnet-mvc/998/play-videos-aspnet-mvc-custom-action-filter,very well explain by Mahesh Sabnis