Play local (hard-drive) video file with HTML5 video tag?

HTMLJavascriptProgramming Scripts

The <video> tag is used to add video, with the following video formats − MP4, WebM and Ogg

On selecting a file via the input element.

The change event is fired

The event is fired for <input>, <select>, and <textarea> elements when a change to the element's value is performed by the user.

Getting File object

The File interface provides information about files and allows JavaScript in a web page to access the content. Object of this type is returned by the files property of the HTML <input> element, which eventually lets you access the list of files selected with the <input type="file"> element.

Object URL pointing to the File object

Use the URL.createObjectURL() static method to create a DOMString containing a URL representing the object given in the parameter.

Set the object URL to the video.src property

Finally, here is how the video is visible. Use the src attribute to add the location (URL) of the video file.

raja
Published on 20-Mar-2018 16:48:25
Advertisements