Normally to embed video into an HTML5 page I use the following:
<video poster="">
<source type="video/mp4; codecs="avc1.42E01E, mp4a.40.2"" src="video/demo.mp4"></source>
<source type="video/ogg; codecs="theora, vorbis"" src="video/demo.ogg"></source>
<source type="video/webm; codecs="vp8, vorbis"" src="video/demo.webm"></source>
</video>
I know, there is no flash fallback. In this situation I didn't need one but that is not the purpose of this question.
My question is how to embed video that can serve both mobile and desktop browsers? Lets say this demo video is somewhere in the range of 20MB. Using the canplaythrough like so:
var onCanPlay = function(event) {
initLoad = false;
video.controls = true;
sb.removeEvent(this, 'canplaythrough');
sb.removeEvent(this, 'load');
return false;
};
if(initLoad) {
video.play();
if(video.readyState !== 4) {
video.addEventListener('canplaythrough', onCanPlay, false);
video.addEventListener('load', onCanPlay, false); //add load event as well to avoid errors, sometimes 'canplaythrough' won't dispatch.
setTimeout(function(){
video.pause(); //block play so it buffers before playing
}, 1);
}
} else {
if(video.currentTime > 0 && video.paused == false) {
video.play();
}
}
Note: Ignore the sb in front of my event handlers. I implement a custom event handler on my frontend framework and I copied this directly from production code.
Is typically the way I handle loading the video enough so that it will play seamlessly back to the user. Which works fine, but on mobile...because its such a large video file it takes a long time to load and quite honestly ruins the experience.
Is the answer to present a mobile version and a desktop?
<video controls>
<source src="demo-small.webm" type="video/webm" media="all and (max-width:600px)">
<source src="demo.webm" type="video/webm">
</video>
I've read a few things about media queries being removed from spec and its got me rethinking if I am even serving video the right way at all. Maybe it would be better to somehow stream the video from the server and avoid the HTML5 tag altogether? If thats the case I could use some direction...