Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seeking in HTML5 video with Chrome

Tags:

I'm having issues seeking in video's using Chrome.

For some reason, no matter what I do, video.seekable.end(0) is always 0.

When I call video.currentTime = 5, followed by console.log(video.currentTime), I see it is always 0, which seems to reset the video.

I've tried both MP4 and VP9-based webm formats, but both gave the same results.

What's more annoying is that Firefox runs everything perfectly. Is there something special about Chrome that I should know about?

Here's my code (which only works in Firefox):

      <div class="myvideo">         <video width="500" height="300" id="video1" preload="auto">           <source src="data/video1.webm" type="video/webm"/>           Your browser does not support videos.         </video>       </div> 

And here's the javascript:

var videoDiv = $(".myvideo").children().get(0) videoDiv.load();   videoDiv.addEventListener("loadeddata", function(){     console.log("loaded");     console.log(videoDiv.seekable.end(0)); //Why is this always 0 in Chrome, but not Firefox?     videoDiv.currentTime = 5;     console.log(videoDiv.currentTime); //Why is this also always 0 in Chrome, but not Firefox?   }); 

Note that simply calling videoDiv.play() does actually correctly play the video in both browsers.

Also, after the movie file is fully loaded, the videoDiv.buffered.end(0) also gives correct values in both browsers.

like image 529
Tovi7 Avatar asked Mar 02 '16 15:03

Tovi7


People also ask

How do I seek a video on Chrome?

How to use it (only 2 steps): 1) Click on any video so that it starts playing 2) Use any of the following Keyboard Controls to make the video seek forward or backward: Keyboard Controls (windows / linux): Ctrl + LeftArrow: Seek backwards 3 seconds Ctrl + RightArrow: Seek forward 3 seconds Ctrl + SpaceBar: Toggle play / ...

Why does my browser not support HTML5 video?

If your browser error "HTML5 video file not found", it means that your browser is not up to date or website pages does not have a suitable video codec. It would help if you communicated with the developer to solve the issue and install all the required codecs.

Does HTML5 work on Chrome?

HTML5 is now compatible with all popular browsers (Chrome, Firefox, Safari, IE9, and Opera) and with the introduction of DOCTYPE, it is even possible to have a few HTML features in older versions of Internet Explorer too.

How to get the currentTime parameter of HTML5 video in chrome?

So to get the currentTime parameter of html5 video to be working in Chrome, you need a server that supports http code 206. For anyone else having this problem, you can double check your server config with curl: This should return code 206.

How do I get chrome to know the file size of video?

Make an API call for you video, then load the blob into URL.createObjectURL and feed that into the src attribute of your video html tag. This will load the entire file and then chrome will know the size of the file allowing seeking capabilities to work.

Is the mp4 extension fine with chrome?

The mp4 file is ok, by testing it on a local html file with the <video> tag all is ok (even with chrome) Is someone using this extension fine with Chrome ? Solved! Go to Solution. Jan 10, 2020 12:14 PM OK. So nothing wrong with the extension.

Why are my videos unseekable on Chrome?

As a result chrome is sending requests for content that doesn't get answered which in turn makes our video's and audio unseekable (and unloopable). Show activity on this post.


2 Answers

It took me a while to figure it out...

The problem turned out to be server-side. I was using a version of Jetty to serve all my video-files. The simple configuration of Jetty did not support byte serving.

The difference between Firefox and Chrome is that Firefox will download the entire video file so that you can seek through it, even if the server does not support http code 206 (partial content). Chrome on the other hand refuses to download the entire file (unless it is really small, like around 2-3mb).

So to get the currentTime parameter of html5 video to be working in Chrome, you need a server that supports http code 206.

For anyone else having this problem, you can double check your server config with curl:

curl -H Range:bytes=16- -I http://localhost:8080/GOPR0001.mp4 

This should return code 206. If it returns code 200, Chrome will not be able to seek the video, but Firefox will, due to a workaround in the browser.

And a final tip: You can use npm http-server to get a simple http-server for a local folder that supports partial content:

npm install http-server -g 

And run it to serve a local folder:

http-server -p 8000 
like image 197
Tovi7 Avatar answered Dec 13 '22 12:12

Tovi7


If you wait for canplaythrough instead of loadeddata, it works.

See this codepen example.

like image 30
Ian Devlin Avatar answered Dec 13 '22 11:12

Ian Devlin