Video.js - HTML5 Video Player

Video.js Blog

Steve Heffernan2011-01-28

Apple adds AirPlay to Mobile Safari

AirPlay is a video feature on iOS devices that lets you play video from your device on your TV, by streaming it to an Apple TV on the same wireless network. Before now this was only available in the iPod and YouTube apps, but with iOS 4.3 (now in beta) it will be available through Mobile Safari as well.

AirPlay Feature in Mobile Safari

In order to allow AirPlay as an option, video publishers have to add an attribute to the HTML5 video tag. <video width=“480” height=“300” controls x-webkit-airplay=“allow”> … We’ll be adding this as a default attribute in the next VideoJS version.

Read the whole story on MacRumors.

Steve Heffernan2010-11-19

Make sites serve you HTML5 video in Safari

John Gruber of Daring Fireball has a cool post on tricking websites to display HTML5 video when they say they can only play Flash. Many sites will tell you they require Flash, even when they actually support HTML5 video for iOS devices.

To add to Gruber’s post, there’s two reasons a site might do this:

  1. They’re trying to protect their content from being easily downloaded, which HTML5 video can’t do very well yet.

  2. They assume everyone with a browser has Flash, and just serve HTML5 video to iOS devices.

So for this first, this is actually a hack to download content some publishers might not want you to. I probably shouldn’t be publishing this since security of the content is one of the main reasons HTML5 video will still take time to spread. But for that purpose, it’s really not hard to figure out.

For the second, it’s kind of lazy implementation of fallbacks. It’s pretty easy to check if Flash is supported, and if not, fall back to HTML5, instead of checking for a specific user agent string. So for sites using VideoJS, this method wouldn’t work, but there also wouldn’t be a need because VideoJS would fallback appropriately to HTML5.

Gruber has disabled Flash in Safari for better performance with video. That says a lot. Most people probably won’t go to same effort he has, but I know he’s not the only one.

Steve Heffernan2010-09-20

iPad & iPhone Video Poster Fix (bonus Javascript Placement Fix)

Bug #1 - Poster Attribute

If you include the poster attribute on the video tag when you’re using <source> tags, the video won’t work on iPads & iPhones using iOS 3. You’ll see a broken play button, or no play button at all. On the iPad specifically, playback in inconsistent. Sometimes it’ll work and sometimes it won’t. This is documented on the Video for Everybody site.

Bug #2 - Javascript in the Head

This is a fun one… If you include Javascript in the head of your page, it’ll break playback on the iPad (also inconsistent). If you move the Javascript to the bottom of the page, and still include a stylesheet, the iPad will work, but the iPhone 3 won’t. I first read about this in a post on the No.inc blog, and then ran into it myself when redesigning the VideoJS site. Their original solution was to put the JS at the bottom of the page for iPads only (fun).

Apple’s iOS4 seems to fix both of these problems on the iPhone, but until iOS4 is available on the iPad, and everyone in the world upgrades their devices, we have to deal with this.

Fix for iOS 3

The problem seems to be some kind of race condition, that trips up the devices. The solution that has fixed both of these for me is to add the playable source directly to the video tag, and tell the video to load (all through Javascript).

I’ve added all this to VideoJS 1.1.2, but here’s the basics of how it works.

var video = document.getElementById("your_video");
var children = video.children;
for (var i=0,j=children.length; i&lt;j; i++) {
  if (children[i].tagName.toUpperCase() == "SOURCE") {
    var canPlay = video.canPlayType(children[i].type);
    if(canPlay == "probably" || canPlay == "maybe") {
      video.src = children[i].src;
      video.load();
      break; // or return or whatever
    }
  }
}

So loop through the source elements, find the one that’s compatible, and add that source to the video src. Then trigger the video’s load() function.

That seems to fix both issues. This will not make the poster show up in either device.It just makes makes the video playable. Sometimes you’ll see it flash the controls and then go back to the big play button.

Any feedback is appreciated.

Let’s go Apple, get iOS4 out to everybody!