-3

Let’s say I have a 4 minute video and I want it to start playing from the 25th second and not from the beginning.

<video autoplay loop id="bgvid">
  <source src="back.mp4" type="video/mp4">
</video>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
m0bi5
  • 8,900
  • 7
  • 33
  • 44
  • @Xufox yup i was thinking the same xD , could you guide me through the javascript method? – m0bi5 Aug 13 '15 at 02:40

3 Answers3

7

Try appending #t=TIME

<video autoplay loop id="bgvid">
  <source src="back.mp4#t=25" type="video/mp4">
</video>

W3.org: Media Fragments URI - http://www.w3.org/TR/media-frags/

MayThrow
  • 2,159
  • 4
  • 24
  • 38
1
document.getElementById('bgvid').addEventListener('loadedmetadata', function() {
  this.currentTime = 25;
}, false);
Max
  • 300
  • 2
  • 6
1

Yes Mohit, I've been looking for a very same functionality earlier on, according to this question, you can try this snippet of javascript code, it worked for me; [it is also a method to stop the video at a certain time]

function playVideo() {
    var starttime = 2;  // start at 2 seconds
    var endtime = 4;    // stop at 4 seconds

    var video = document.getElementById('player1');

    //handler should be bound first
    video.addEventListener("timeupdate", function() {
       if (this.currentTime >= endtime) {
            this.pause();
        }
    }, false);

    //suppose that video src has been already set properly
    video.load();
    video.play();    //must call this otherwise can't seek on some browsers, e.g. Firefox 4
    try {
        video.currentTime = starttime;
    } catch (ex) {
        //handle exceptions here
    }
}
Community
  • 1
  • 1
Pouya Ataei
  • 1,959
  • 2
  • 19
  • 30