Multiple stream sources with video-js - video.js

I'd like to have two m3u8 sources, so when one is not available it skips to the next one. Is this possible?
I usually do that with html5 video as this:
<video controls="" height="" poster="" width="">
<source src="xxx.m3u8" type="application/x-mpegURL"></source>
<source src="xxx.m3u8" type="application/x-mpegURL"></source>
</video>
In don't know how to do it with video.js, as just putting the two sources doesn't work.
Thanks.

That's what u need - VideoJS Error Event

Related

html 5 video will not autoplay

I have a video that should autoplay, but it will not.
I had it set up like this:
<video id="video" autoplay muted playsinline loop
poster="http://res.cloudinary.com/situ-live/video/upload/f_auto/Situ-Sizzler-Web-Clip-v05-01_auvu5o.jpg"
#video>
<source
src="http://res.cloudinary.com/situ-live/video/upload/f_auto/Situ-Sizzler-Web-Clip-v05-01_auvu5o.webm"
type="video/webm">
<source
src="http://res.cloudinary.com/situ-live/video/upload/f_auto/Situ-Sizzler-Web-Clip-v05-01_auvu5o.mp4"
type="video/mp4">
<source
src="http://res.cloudinary.com/situ-live/video/upload/f_auto/Situ-Sizzler-Web-Clip-v05-01_auvu5o.ogv"
type="video/ogg">
</video>
As you can see, it's muted so according to this document it should play, but it will not.
I tried to add a function to the canplay method, but when I do that I get this error:
DOMException: play() failed because the user didn't interact with the document first.
which is what lead me to the document above.
Does anyone know how I can solve this?
if you just use the HTML you have in question have in - the video plays just fine.
If you try to force it to play with JS - you'll get this error - as it is a way people try to get around blocking autoplay in the browser. for play() in JS to work, the user must first click somewhere on the page.
by default in newer versions of browsers, because of the user experience and prevention of sudden playing of the video, sometimes autoplay attribute won't work.
you can just fix it by a line of javascript in the page load function:
document.getElementById("video").play();
that's it!

html video tag not working on internet explorer

I am using a video background for my website. Which runs fine on all browser on local host. But when I upload it to ipage server, it does not run on IE11. Here is my code.
<video autoplay loop muted class="visible-lg visible-md">
<source src="video/sh.mp4" type='video/mp4" codecs="avc1.4D401E, mp4a.40.2"'>
<source src="video/shanonaction.ogv" type="video/ogg">
</video>
First check your IE version. If it is lower than 9, you need to use the Flash player. You can also used embed in Internet Explorer 8 or lower.
Like this:
<pre>
<video id="Video1" controls width="100%" height="auto" poster="pic.png">
<source src="video.mp4" type='video/mp4;' />
<embed src="video.mp4" wmode="opaque">
<param name="wmode" value="opaque" />
</embed>
</video>
</pre>
It works for me.
This took me a really long time to figure out. No one seemed to know.
The issue is the pixel size of the video.
For some odd reason. Internet Explorer 11 will simply ignore any video whose height is more than around 1000 pixels. so a 1080p html 5 video will not load, but a 720p will.

Force .webm instead of .mp4

I have a video slider with .webm,.mp4 & .ogv media formats.
as webm is a much smaller size, I want to force the use of .webm if the browser/device can support the format.
You can specify a priority of formats by the way you arrange the source tags for the video. If the browser supports the first format listed it will use that, if not it will continue to the next and so on.
Example:
This will try the webm format first, if browser cannot play it the theora version is tried and finally mp4 if that didn't work either (finally a fallback if none are supported) (borrowed from wikipedia) -
<video poster="movie.jpg" controls>
<source src="movie.webm" type='video/webm; codecs="vp8.0, vorbis"'>
<source src="movie.ogv" type='video/ogg; codecs="theora, vorbis"'>
<source src="movie.mp4" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
<p>This is fallback content to display for user agents that do not
support the video tag.</p>
</video>

What is the best container for html5-videos?

I have some videos I try to convert with Blender into a format which could be rendered by the most modern Browsers. I tried many different Settings and neither IE nor Firefox was able to decode the files. (Windows Media Player always did.)
I use the following html code:
<video width="320" height="240" controls>
<source src="data/test.avi">
Your browser does not support the video tag.
</video>
Is this correct?
I tried different formats, codecs and reslolutions. (mpeg-4, h.264, ogg, theora).
Do you have any suggestions?
Edit:
Ogg-Theora does run in Firefox and Chrome, but not in IE.
This is and has always been an issue, that is, format "wars" - which format to use, both for audio and video.
Unfortunately (depending on what angle you look at it) there is not one single format to rule them all, so you actually have to provide as many as "possible". By possible at least the three main formats:
MP4
Ogg Video
WebM
You can choose priority by defining the source tag in the order you prefer them to be used:
<video width="320" height="240" controls>
<source src="data/test.mp4" type="video/mpeg" />
<source src="data/test.ogv" type="video/ogg" />
<source src="data/test.webm" type="video/webm" />
Your browser does not support the video tag.
</video>
Hope this gives some input.

How do I tell video.js which mp4 source to use for mobile?

I have two mp4 source files, one encoded for desktop and one for mobile. Video.js is serving the wrong one to iPhone and iPad and they cannot be played. How can I tell Video.js which one to serve to these devices?
--Edit to add more info and clarify:--
I am using Video.js version 3.2.0, but the same problem occurs in 4.0.
The reproducible problem I am having is that some videos are not playing on older iOS devices - 1st gen iPad and iPhone 3GS. I believe it is because Video.js is playing the first mp4 in the source list instead of the one encoded for mobile.
My Video.js player code looks like this:
<video id="video_1" class="video-js vjs-default-skin"
controls preload="auto" width="640" height="390"
poster="https://s3.amazonaws.com/sightingsreport/videos/1748/dthumbnail_0000.png"
data-setup="{}">
<source src="https://s3.amazonaws.com/sightingsreport/videos/1748/default.mp4"
type='video/mp4' />
<source src="https://s3.amazonaws.com/sightingsreport/videos/1748/movie.webm"
type='video/webm' />
<source src="https://s3.amazonaws.com/sightingsreport/videos/1748/mobile.mp4"
type='video/mp4' />
</video>
If I move the mobile.mp4 source to be first in the list, it plays on the old iOS devices, but it also appears to use that one on non-mobile devices.
I thought Video.js was supposed to automatically serve the best source file for the device. Is that not correct?
What is the best way to handle this?
i would do it with php like ..
<?PHP
$isiPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$isiPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$isiPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$isiDevice = $isiPod || $isiPhone || $isiPad ;
?>
..and..
<video id="video_player" class="video-js vjs-default-skin">
<?PHP if($isiDevice ) { ?>
<source src="mobile.mp4" type='video/mp4' />
<?PHP } else { ?>
<source src="desktop.mp4" type='video/mp4' />
<?PHP } ?>
</video>
This is a major bug in video.js. It checks for canPlayType() on each of the sources and select only the first one to use instead of keeping the multiple sources that the browser can select from.
Basically, it's impossible right now to have a fallback video of the same type.
I've submitted an issue on Github related to this:
https://github.com/videojs/video.js/issues/662