How to get html content from a webview?

How can I get an HTML 5 media player to stream video content as opposed to downloading the video file?

  • My project has an existing silverlight player that streams ismv video files and the technology I believe is behind that is IIS media services. I want to change the silverlight player with a HTML5 player. The video files I will use are mp4. How can I stream this video content with the HTML 5 player as opposed to downloading the whole file when playing the video.?

  • Answer:

    I recently needed this, and found that a simple .Net script did the trick of streaming H.264/AAC MP4 files.  I also found that this method is very processor and memory intensive. First, make a folder called videos at the root of your web server, and put your mp4s in it. Next, make a file called "streammp4.ashx" at the root of your web server and insert this code into it. <%@ WebHandler Language="C#" Class="streammp4" %> using System; using System.Web; using Page on system.io; using System.Collections.Generic; public class streammp4 : IHttpHandler { private void RangeDownload(string fullpath,HttpContext context) { long size,start,end,length,fp=0; using (StreamReader reader = new StreamReader(fullpath)) { size = reader.BaseStream.Length; start = 0; end = size - 1; length = size; context.Response.AddHeader("Accept-Ranges", "0-" + size); if (!String.IsNullOrEmpty(context.Request.ServerVariables["HTTP_RANGE"])) { long anotherStart = start; long anotherEnd = end; string[] arr_split = context.Request.ServerVariables["HTTP_RANGE"].Split(new char[] { Convert.ToChar("=") }); string range = arr_split[1]; if (range.IndexOf(",") > -1) { context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size); throw new HttpException(416, "Requested Range Not Satisfiable"); } if (range.StartsWith("-")) { anotherStart = size - Convert.ToInt64(range.Substring(1)); } else { arr_split = range.Split(new char[] { Convert.ToChar("-") }); anotherStart = Convert.ToInt64(arr_split[0]); long temp = 0; anotherEnd = (arr_split.Length > 1 && Int64.TryParse(arr_split[1].ToString(), out temp)) ? Convert.ToInt64(arr_split[1]) : size; } anotherEnd = (anotherEnd > end) ? end : anotherEnd; if (anotherStart > anotherEnd || anotherStart > size - 1 || anotherEnd >= size) { context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size); throw new HttpException(416, "Requested Range Not Satisfiable"); } start = anotherStart; end = anotherEnd; length = end - start + 1; fp = reader.BaseStream.Seek(start, SeekOrigin.Begin); context.Response.StatusCode = 206; } } context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size); context.Response.AddHeader("Content-Length", length.ToString()); context.Response.WriteFile(fullpath, fp, length); context.Response.End(); } public void ProcessRequest(HttpContext context) { string filename = context.Request["source"]; string mimetype = "video/mp4"; string fullpath=context.Server.MapPath("videos/"+filename); if (Page on system.io.File.Exists(fullpath)) { context.Response.ContentType = mimetype; if (!String.IsNullOrEmpty(context.Request.ServerVariables["HTTP_RANGE"])) { RangeDownload(fullpath,context); } else { long fileLength = File.OpenRead(fullpath).Length; context.Response.AddHeader("Content-Length", fileLength.ToString()); context.Response.WriteFile(fullpath); } } else { throw new HttpException(404, "Video Not Found Path:"+fullpath); } } public bool IsReusable { get { return false; } } } Finally, make a file called index.html and put this into it <video src="sreammp4.ashx?source=myfile.mp4" width="640" height="480" controls></video>

Toan Tran at Quora Visit the source

Was this solution helpful to you?

Other answers

You can use Media Element JS  http://mediaelementjs.com/ Its one of the leading jQuery plugin which turn a simple HTML 5 video element such as : <video src="myvideo.mp4" width="320" height="240"></video> Into a fully function crossbrowser media player.

Syafrullah Djaya

I’m gonna be spammy here in suggesting you to try http://Brid.Tv but please bear with me. If I understood you right you are looking to change your existing player? If so, we might be the best choice.First of all, it is HTML 5playe with support for AMP HTML for your mobile users (if needed).Second it comes with tons of options you might need from monetizaion to customization of player design.Thirdly, we have support for https://www.brid.tv/bridtv-player-adopting-new-streaming-protocols-support-hls-mpeg-dash-new-ad-tag-waterfall-feature-pre-rolls/ streaming protocols making your streaming super easy.Finally, it’s completely FREE and easy to manage

Nicholas Bodell

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.