HTML5 video (video.js) not loading in Chrome

匆匆过客 提交于 2019-12-04 16:26:59

I had same Problem after wrong Conversion. Try to expand the problem in chrome console to check which video file produces the error. I think its the .mp4 version. I used "miro video Converter" to convert from mp4 to mp4 and it works well but you get a little quality loss...

after that its possible that you have same problem like me... chrome doesnt play .webm files... no idea why :(

sry about bad english ^^

The good thing (or bad) is the fact that this is not the VideoJS issue. I had the same problem. Looking on the Internet we can find some informations (for example: https://github.com/flowplayer/flowplayer/issues/423) and it considered to be a Chrome bug. Issues was reported in JWPlayer and VideoJS forum as well.

AFAIK the only way to bypass this is loading webm file:

<source src="test.webm" type="video/webm" />

I tried to put webm source before mp4. Chrome recognized webm as "good" source and play it well. Sadly FF and IE won't play a thing. So we need to chose one format after browser-check (what is wrong but I in this point I don't see another way; this is not JS feature related problem...).

Why browser detection is generally bad idea? You can read more about this in Test-Driven Javascript Development book or here: http://jibbering.com/faq/notes/detect-browser/

As quick fix you can use something like this:

/* load webm for chrome */
if (window.chrome) {
    videojs('videoTagId').src({ type: "video/webm", src: 'path/to/file.webm' });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!