Control start position and duration of play in HTML5 video

We have a video (13 minutes long) which we would like to control using HTML5. We want to be able to let our users control and select the parts of the video they want to play. Preferably this control would be through 2 input fields. They would input start time (in seconds) in first box and input duration to play (in seconds) in second box. For example, they might want to start the video 10 seconds in and play for 15 seconds. Any suggestions or guidance on the Javascript needed to do this?

Note: I have found the following:

  • Is it possible to restrict forwarding in HTML5 video?
  • Set videoElement.currentTime in Hulu video player doesn't work, and breaks the player
  • Brightcove HTML5 Player full screen event
  • How to take a snapshot of HTML5-JavaScript-based video player?
  • Javascript video blob and progressive download
  • How to save capture video file in window 8 metro app?
    • Start HTML5 video at a particular position when loading?

    But it addresses only starting at a particular time, and nothing with playing the video for a specified length of time.

  • Change Video (Different quality) file in html5 through Jquery
  • getUserMedia() video size in Firefox & Chrome differs
  • Detecting that the peer's browser was closed in a webrtc videochat
  • Prevent HTML5 video from being downloaded (right-click saved)?
  • HTML5 Video: Are there any benefits to using a source element over the src attribute
  • Adding sources to HTML5 video in javascript?
  • 4 Solutions collect form web for “Control start position and duration of play in HTML5 video”

    You could use the timeupdate event listener.

    Save the start time and duration time to variable after loadedmetadata event.

    // Set video element to variable
    var video = document.getElementById('player1');
    var videoStartTime = 0;
    var durationTime = 0;
    video.addEventListener('loadedmetadata', function() {
      videoStartTime = 2;
      durationTime = 4;
      this.currentTime = videoStartTime;
    }, false);

    If current time is greater than start time plus duration, pauses the video.

    video.addEventListener('timeupdate', function() {
      if(this.currentTime > videoStartTime + durationTime){

    If you are able to set start time and end time of video while setting the video url.
    you can specify the start and end time in the url itself like

    src="future technology_n.mp4#t=20,50"

    it will play from 20th second to 50th second.

    There are a lot of nuances to using the javascript solution proposed by Paul Sham. A much easier course of action is to use the Media Fragment URI Spec. It will allow you to specify a small segment of a larger audio or video file to play. To use it simply alter the source for the file you are streaming and add #t=start,end where start is the start time in seconds and end is the end time in seconds.

    For example:

    var start = document.getElementById('startInput').value;
    var end = document.getElementById('endInput').value;
    document.getElementById('videoPlayer').src = ''+start+','+end;

    This will update the player to start the source video at the specified time and end at the specified time. Browser support for media fragments is also pretty good so it should work in any browser that supports HTML5.

    Extend to michael hanon comments:
    IE returns buffered.length = 0 and seekable.length = 0. Video doesn’t play. So solution:


    will not works in IE. If you would like to support IE only way is to use javascript to seek video just after start from 0 second.