CHAPTER 10

image

The Truth About Audio and Video in HTML5

Both <audio> and <video> are welcome additions to the HTML spec. We don’t use proprietary tools (such as Flash) to display images, so why should we need them to play audio or video?

Don’t get me wrong: I’m not here to bash Flash. Without it we wouldn’t have YouTube, Vimeo, and the video revolution that has taken place over the past few years. And Flash still provides advanced video features (such as live streaming, full-screen playback, and DRM, as icky as DRM is) that have either no or very preliminary implementations as open standards.

Nevertheless, HTML5 <video> and <audio> have become almost mandatory for media delivery for one reason: iOS. Given Apple’s decision not to allow Flash on its mobile devices, the only way to embed video and audio so it’s available for iPhone, iPad, and iPod touch users is to use these new HTML5 elements.

But it doesn’t stop at iOS. As we saw in the previous chapter, in late 2011 Adobe announced it was abandoning the Flash plug-in on mobile altogether and shifting its focus to native apps and HTML5.(For more on the demise of the Flash plug-in, check out the discussion in the previous chapter.)

We’re racing toward a post-Flash future. Unfortunately, our open technologies are just not ready to replace all that Flash offers. Web standards won, and we’re going to get caught with our pants down if we’re not careful. That leaves apps to fill the gaps, taking us back to the ’90s with platform-specific software.

We’ll return to the issue of our post-Flash future shortly. For now, let’s look at the new HTML5 <audio> and <video> elements as they currently stand. While these elements are specified quite simply, issues outside the spec make their implementation interesting, to say the least. First let’s look at the basics.

Native <video> and <audio> in Action

So, how do we use these new elements? In theory, it’s pretty simple. Let’s start with <audio>.

The <audio> Element

For audio, we can use this:

<audio controls autoplay loop muted preload="auto">
   <source src="myaudio.ogg" type="audio/ogg">
   <source src="myaudio.mp3" type="audio/mpeg">
   <!-- Fallback content, such as a Flash player, here -->
</audio>

This will give us something like the Chrome example shown in Figure 10-1 (note that browsers render the <audio> element however they want, and there can be considerable difference in player size).

9781430264156_Fig10-01.jpg

Figure 10-1. The default audio player in Chrome, Safari, and Firefox (from top to bottom)

Let’s run through this. First, you can stick the src attribute in the opening <audio> tag if you like, instead of using the <source> element. But because of mind-bogglingly annoying issues with codec support (which we’ll delve into shortly), we often need to specify two source files for maximum HTML5 compatibility.

And that’s what the <source> element is for. Browsers work through the list of <source> elements until either they find a file format they support or (if we’ve included one) they get a fallback option—perhaps a link to the file or (more commonly) a Flash media player. (See the following resources for a tutorial on implementing a Flash fallback.)

Both <audio> and <video> are implemented in a backward-compatible way, insofar as older browsers (such as IE8) will ignore the <audio> and <source> elements altogether (IE8 just sees those elements as generic tags, like <mymadeuptag>). This means whatever fallback content we include will be visible to the older browsers but ignored by the modern ones.

We can also use scripting to give a Flash fallback to browsers that support the <audio> (or <video>) elements but not the codec we’ve used. We’ll look at media players that do the heavy lifting for us at the end of this chapter.

<audio> Attributes

Back to the <audio> element. The attributes controls, autoplay, loop, and muted are boolean attributes—including them makes them true, and excluding them makes them false. (But given that autoplay and loop are tools of the devil, we should probably always leave them out.) The muted attribute makes the browser’s player default to mute (though support for this may be patchy), and the controls attribute tells the browser to use its native controls. (The elements can also be controlled through the JavaScript API.)

There’s also a preload attribute that’s not boolean but instead can be none, metadata (preload the metadata for the file only), or auto, which usually means the browser will preload it. But this setting is only a hint—iOS will never preload data because users could be on expensive mobile data networks. (Browser support for preload is relatively new.)

You may have also noticed the type attribute on the <source> elements. Here’s an example:

<source src="myaudio.mp3" type="audio/mpeg">

This attribute tells the browser what container format was used so it can work out whether it supports the file format without having to start downloading it to check. Sadly, audio format support in modern browsers is a bit of a mess, as we’ll see shortly.

This is just a brief description of the <audio> element. For implementation I suggest you use an HTML5-friendly, JavaScript-based media player. It will help smooth out the implementation issues and save you from reinventing the wheel, which is especially helpful given the immature <audio> implementations in current browsers. We’ll look at our media player options at the end of this chapter. (But if you want something simple you can drop in right now, try audio.js: http://kolber.github.com/audiojs/.)

However, for audio file preparation, you need to understand the issues around codecs that we’ll discuss after we look at the <video> element. We’ll also look at HTML5 audio for games later in the chapter and touch on the flaws and future of <audio>.

The WebAudio API

At the time of this writing, the WebAudio API is a working draft and appears to be well on its way to making it into some version of HTML soon (see it live here: www.w3.org/TR/webaudio/). It is currently supported by all major browsers except IE.

This is a huge step forward for audio in JavaScript, but lack of support from the world’s largest browser means developers should be hesitant to invest too much time and effort or should invest in a fallback along with it. At the time of this writing, Microsoft is considering WebAudio in “a future version of IE,” and its development ticket tracking the issue can be seen here: http://connect.microsoft.com/IE/feedback/details/799529/web-audio-api-support.

More on how to use the WebAudio API to control audio streams is covered in the following resources and tutorials.

For more <audio> resources, see the following:

The beauty of having the <audio> and <video> elements available as ordinary HTML is you can style them with CSS, including advanced CSS3. Check out the beautiful Zen Audio Player (shown in Figure 10-2, playing Girl Talk no less) to see what’s possible: https://github.com/simurai/ZEN-Player.

9781430264156_Fig10-02.jpg

Figure 10-2. The Zen Audio Player really is a thing of beauty—be sure to see it in action

The crucial thing to understand with <audio> is the codec situation, so keep reading and we’ll get delve into it after a brief trip through the <video> element.

The <video> Element

For video, we can use this:

<video controls autoplay loop muted preload="auto"
poster="myvideobackground.jpg" height="250" width="300">
   <source src="myvideo.webm" type="video/webm">
   <source src="myvideo.mp4" type="video/mp4">
   <!-- Fallback content, such as a Flash player, or a link to the file here -->
</video>

(If you want to see what’s really involved with <video> implementation, including browser issues, setting MIME types, and more, see Kroc Camen’s wonderfully thorough “Video for Everybody” article: http://camendesign.com/code/video_for_everybody.)

As you can see, it’s a similar setup to the <audio> example. In fact, the controls, autoplay, loop, muted, and preload attributes all behave the same way. But they’re not quite the devil’s tools as they are for audio. Here we could have an autoplay, looping video advertisement that’s muted until the user decides otherwise.

And just like <audio>, we have to deal with codec support issues by specifying multiple video files for maximum HTML5 compatibility. We use the <source> tag to give browsers a list of video files, and they use either the first one they support or the fallback content (such as Flash Player). The type attribute gives browsers a hint as to which file they should try to play. We’ll discuss this after looking at the codec situation.

The <video> element has several of its own unique attributes. The main one is poster, which is the static image that’s displayed until the first frame of the video is available. This may be only for a second or two in some cases, but on mobile devices (such as iOS) the poster is shown until the user initiates playback.

(At least that’s the theory. IE’s handling of the poster image is quirky for versions 9 and 10, as Ian Devlin found: www.iandevlin.com/blog/2011/12/html5/the-problem-with-the-poster-attribute. The bug appears to be fixed in IE11. Older versions of iOS and Android had problems as well, but they’re largely unused at this point, while IE9 and 10 continue to have significant percentages of the market. Speaking of Ian Devlin, he has a great post on how to implement poster in newer browsers here: www.iandevlin.com/blog/2013/03/html5/html5-video-and-background-images.)

The height and width attributes are also specific to the <video> element. But again, because the <video> element is just another bit of HTML, it can be styled and manipulated with CSS, including advanced CSS3. You can transform and animate the video itself, add shadows, and so on. This is one of the coolest things about <video> being just another element in the DOM. You can even use the <canvas> element to manipulate your video source, as discussed here: http://html5doctor.com/video-canvas-magic/.

Video Accessibility

Media accessibility is also being developed. A <track> element has been added to the spec to provide captioning. Or, as the spec puts it: “The track element allows authors to specify explicit external timed text tracks for media elements” (http://dev.w3.org/html5/spec/Overview.html#the-track-element). The <track> element sits between the <video></video> tags and looks like this:

<track kind="subtitles" src="moviecaptions.en.vtt" srclang="en" label="English">

You can find presentations and discussions on the issues and proposed solutions at http://blog.gingertech.net/2011/03/29/webvtt-explained/ and at www.iandevlin.com/blog/2011/05/html5/webvtt-and-video-subtitles.

Currently only IE10, Opera, and Chrome support <track>. For more, see “Getting started with the HTML5 track element” (www.html5rocks.com/en/tutorials/track/basics/).

API and Resources

The new HTML5 JavaScript API for media also handles video playback, which lets you roll your own controls. It’s covered in the following resources and tutorials.

For more <video> resources, see the following:

The savior for <video> is stand-alone JavaScript players, which let us use one file, HTML5 (and a given codec) where it’s supported, and Flash everywhere else.

We’ll get to the media players in a moment. In the meantime, grab a fistful of hair, and get ready to pull.

Codecs, You’re Killing Me

OK, so HTML5 for modern browsers and Flash as a fallback for older browsers. Got it.

Not so fast. This is HTML, which isn’t so much “Anything that can go wrong will go wrong” as “Anything that can cause disagreement will cause disagreement.” And the disagreement here is codecs, for both audio and video.

If you use an <image> tag, all browsers can display the image whether it’s a JPEG, GIF, or PNG—there’s no mandatory format.

The HTML5 spec (reluctantly) takes a similar view with the <audio> and <video> tags by not specifying a specific format (in other words, a codec) for audio or video.

You specify the format you want to use, and it’s up to the browser to support it (or not, as we’ll see).

Now if browser vendors all agreed on a single format (or several formats), we’d have universal HTML5 audio and video in all modern browsers. Unfortunately, that hasn’t happened. Here’s what the HTML5 editor Ian Hickson said on the situation in mid-2009 (http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2009-June/020620.html):

After an inordinate amount of discussions, both in public and privately, on the situation regarding codecs for <video> and <audio> in HTML5, I have reluctantly come to the conclusion that there is no suitable codec that all vendors are willing to implement and ship.
I have therefore removed the two subsections in the HTML5 spec in which codecs would have been required, and have instead left the matter undefined, as has in the past been done with other features like <img> and image formats, <embed> and plug-in APIs, or Web fonts and font formats.

The Patent Problem

The problem with agreeing on a codec comes down to patents. Some media formats—including MP3 for audio (yes, the humble .mp3) and the popular H.264 format for video (usually used in .mp4 and .mkv files)—have patents that make companies cough up licensing fees to use the decoders in their products.

For big companies such as Apple, Microsoft, and Adobe (with Flash), this isn’t a problem—they support both MP3 and H.264. But for ideological and financial reasons, Opera and Mozilla didn’t want to support H.264 for video. (In early 2011 Google threatened to drop H.264 support from Chrome on the desktop, but as of this writing that has yet to happen. See the post announcing the drop that hasn’t happened: http://blog.chromium.org/2011/01/html-video-codec-support-in-chrome.html. Also see where Google agrees that its VP8 format does violate some H.264 patents: www.businesswire.com/news/home/20130307006192/en/Google-MPEG-LA-Announce-Agreement-Covering-VP8.)

In 2013 Cisco offered to solve all of this for video by open sourcing the H.264 codec. Mozilla agreed to support it, but Opera still doesn’t, and Google still does but doesn’t want to (http://gigaom.com/2013/10/30/google-sticks-with-vp8-opposes-ciscos-push-for-h-264/). All of the browsers have also standardized on MP3 as an audio format, but Mozilla and Opera remain critics of it for its patent restrictions. At the time of this writing, Mozilla doesn’t support MP3 in Firefox for Macintosh, but this appears to be coming very soon.

To further complicate things, in 2012, just as it seemed like MP3 would finally win out in audio codecs, Mozilla began championing its Opus codec for audio, adding yet another to the mix. At the time of this writing, Firefox and Chrome support it natively. (Chrome users must activate it through chrome://settings using the enable-opus-playback flag, which everyone does right?) Opera may add support soon, and it’s unlikely that IE will get on board.

At the time of this writing, it appears that H.264 and MP3 will still be the winners, but as of yet there’s still no single codec in video that all of the major desktop and mobile browsers support.

What are the alternatives? In the audio department, Mozilla and Opera champion the patent-free Ogg format (ditto for video, but it’s seen as inferior). And in mid-2010 Google released the theoretically patent-free WebM video format (after buying it for a cool $100 million) to provide a “Can’t we all just get along?” solution for video that everyone could use, thereby resolving the deadlock.

So, everyone could just switch to those, right? Not quite. For something to be truly “patent-free,” it generally has to be proven in court. So, Microsoft and Apple take a “better the devil you know” approach and pay royalties for the codecs they use, especially with video and H.264. They figure it’s better to do that than opt into supposedly “patent-free” technology that may not be so patent-free after all and could make them liable in the future. Indeed, questions are already being raised about potential WebM patent infringement, so these are valid concerns. (That’s the condensed version, in any case!)

Perhaps making matters better, in 2013 Cisco decided to offer everyone a patent-free version of H.264 to end the debate and make it the default standard. Mozilla got on board and promised H.264 in Firefox, but Google is still holding out. Cisco and others take the position that H.264 is the de facto and industry standard anyway, so it’s time to get on board. Google takes the position that it’s dangerous to rely on a technology that’s not truly open because Cisco could pull the free license at any time and because it views H.264 as a dated technology impeding innovation.

In Google’s view, everyone should adopt the open and innovative WebM and embrace the future. If only things were that simple.

H.264 Is Baked In

Even if everyone could use WebM for video, it’s not like Apple or Google (with Android) could just push out a software update and have everyone running WebM for video (especially on mobile).

Why not?

H.264 uses hardware acceleration in mobile devices (as well as desktop and other devices), which is how we get to watch high-quality video on low-powered devices without destroying battery life.

Throw in additional issues, such as the industry toolchain built around H.264, and the situation gets even murkier. You can see why a wholesale switch from H.264 would be difficult (at least in the short to medium term) even if everyone did decide to move in that direction. This is how one Hacker News commenter put it (http://news.ycombinator.com/item?id=2106285):

The digital video world runs on H.264, it has deep, complicated, expensive internal toolchains to support it, legacy archives encoded in it, basically entire businesses built around it. The video production world is far larger and more complex than you're picturing it.

H.264 on mobile is, for all vendors and for the foreseeable future, a fact of life.

Google Threatens to Take Chrome WebM Only…and Then Doesn’t

Let’s look at who supports what.

Google, as mentioned, announced in 2011 it was going to remove H.264 support from Chrome to focus on WebM (see the announcement: http://blog.chromium.org/2011/01/html-video-codec-support-in-chrome.html), but as of this writing in late 2013, that has yet to materialize. Google-owned YouTube transcodes all videos into WebM so it can serve both WebM and H.264. Yep, Google is duplicating its entire YouTube library. But for what purpose? As long as Google continues to provide both codecs, H.264 remains the one codec everyone can use, and WebM continues to look like an interesting technical exercise with no important future.

As for Microsoft, it shares Apple’s position and is sticking with H.264 (see: www.fastcompany.com/1723373/microsoft-sides-with-apple-over-google-onh264-video). Microsoft allows native WebM playback in its desktop players if a user installs the codec, but there’s no shipping support, and  Microsoft doesn’t support it in its mobile browsers at all.

Google and Microsoft then released tit-for-tat plug-ins. Google released a WebM plug-in for IE9 (http://tools.google.com/dlpage/webmmf), though whether it gets any significant adoption remains to be seen. Microsoft has in turn released an H.264 plug-in for Chrome (see http://blogs.msdn.com/b/interoperability/archive/2011/02/01/greater-interoperability-for-windows-customers-with-html5-video.aspx) and Firefox (see http://blogs.msdn.com/b/interoperability/archive/2010/12/15/html5-video-and-interop-firefox-add-on-provides-h-264-support-on-windows.aspx) for its Windows 7 users who use Firefox.

After Cisco offered H.264 for free, Mozilla agreed to support it, and there was hope for a consensus. Yet Opera still hasn’t gotten on board and has had little to say about it, and Google is pushing ahead with WebM anyway.

Finally, though this barely seems to matter anymore, Adobe Flash, once the only reliable option for multibrowser video, also doesn’t support WebM. It said it would back in 2011 but still hasn’t implemented it as of 2013.

So, let’s review: everyone supports H.264, even Google, which said it wouldn’t. No one really supports WebM except Google. Which codec do you think is going to win?

For a further breakdown on browser and device compatibility, see the handy chart here: http://mediaelementjs.com.

Codecs: What to Do?

Phew! So, where does that leave us?

If you want maximum native HTML5 support—including Opera—you need to store two copies of your audio (MP3 and Ogg Vorbis) and potentially three copies of your video files (H.264, WebM, and Ogg Theora for legacy support in Firefox 3.x). Having to encode and store so many different versions is a royal pain in the ass, but there you go.

Alternatively, you can do one of the following:

  • Use MP3 for audio, which works natively in all of the modern incarnations of major browsers on desktop and mobile (except Firefox for Macintosh, but this is coming soon, and Opera).
  • Use H.264 for video, which works natively in iOS, Safari, Firefox, and IE9.
  • Use a media player (or script your own) that uses Flash Player for older and non-codec-supporting devices, given Flash can play MP3 and H.264 in any Flash-enabled browser or device.

Given we need H.264 for iOS (and mobile in general), this scenario—which I would wager will be the most common—means Opera (and potentially Chrome someday if it really drops H.264) will end up getting Flash. That’s right—those who stood up for free, open software will end up with proprietary, closed Flash. That is more ironic than a hipster’s mustache.

(Alternatively, you can, as mentioned, double encode your video and provide a separate WebM file in a secondary <source> element for broad native HTML5 support in modern browsers.)

Reality Bites

The reality may be a little different, though. For one, Google has yet to drop H.264 support, and Firefox finally added it after much debate. Can Opera’s support really be that far off? It’s difficult to imagine Opera holding out indefinitely. The practical implication for this is encoding media in H.264 (with a Flash fallback for older browsers) and MP3 (ditto) will be sufficient in the long term.

Video Types…Oh My

Now that you (ideally) understand the complexity of the codec situation and the way browser support for each codec differs, let’s look at how we can tell browsers which codecs we’re using so they can make smart decisions about which video they load.

That brings us to the one video attribute we haven’t discussed—the type attribute on the <source> element. Here’s an example:

<source src="myvideo.mp4" type="video/mp4">

This attribute tells the browser what container and codec is used for the video specified in the src attribute. In the previous example, we’ve specified only what container format is used by listing its MIME type (that is, media format type). The MIME type shown earlier tells the browser “This file is a video using the mp4 container format.” Container formats like mp4 are a little like zip files, in that they are simply a container for the actual video and audio files, which are encoded with specific codecs and wrapped up to make the final video file. (The type attribute can also be used on the <video> element itself, not just a nested <source> element, if you’re using only one file. The same goes for <audio>.)

The information we put in the type attribute is just a hint to the browser, but it’s not necessary for browsers to play the video. What is necessary is to edit your .htaccess file on Linux or similarly configure IIS to make sure your server sends this file with the right MIME type, as the instructions describe at http://mediaelementjs.com/ or at http://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx and are covered elsewhere (for example, the “Video for Everybody” article mentioned earlier).

We can also specify both the container format and the codec used. Here’s an example:

<source src="myvideo.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>

Here we’ve specified the container format and the codecs for both the video and the audio in the source file. (The video codec is a flavor of H.264, along with the AAC audio codec. Note we also have to use single quotes for the type attribute here because the codecs parameter uses double quotes.)

What’s the point of all this? Well, specifying the type attribute means the browser doesn’t have to start downloading every listed file just to check whether it can play it. It can scan the markup and potentially start preloading the video file it supports. Leaving it out, however, isn’t the end of the world. The following is from “The State Of HTML5 Video” by LongTail Video, written in 2012 (www.longtailvideo.com/html5/):

Every browser supports the <source> tag for loading multiple sources. Our tests show that including the type attribute prevents some preloading, but breaks compatibility with Android 2.2. Setting the codecs in the type attribute has no impact in any browser.

Note the Android 2.2 compatibility issue. The comment about codecs suggests that from LongTail’s testing we (by and large) need to specify only the container and the browser will have a go at loading it.

Querying Supported Video Types with JavaScript

We can also query the browser using the <video> JavaScript API and its canPlayType() method to see which formats the browser supports. For example, with the codecs we specified earlier (avc1.42E01E, mp4a.40.2), browsers that support these formats (Safari and IE9+) will respond with probably, which is as close to “Yes, we support this file” as we get in HTML5.

If we specify only the container format (video/mp4), Safari and IE9+ (for example) respond with maybe because they know they can read that container format but don’t know what codecs lie inside. Browsers that don’t support a given container or codec format just return a null string.

Things get awfully complicated, though. Here are the three variables we have to deal with:

  • Browser response: Because of the complexities of encoding media (and especially video), browsers only know for sure that they can’t play formats they don’t understand. In those cases, they return a null string (when queried through the canPlayType() method). Beyond that, the HTML5 spec says they must return either maybe or probably depending on the browser’s confidence it can play a certain file based on the information we’ve provided.
  • Containers and codecs: There are container formats such as mp4, and there are the actual codecs or, more accurately, flavors of the actual codecs (such as avc1.42E01E) that can be queried.
  • Browser support: Finally, as we’ve seen, the codec support from the major browsers is a pretty complex situation.

Therefore, we have multiple browsers supporting multiple container/codec varieties (for both audio and video) and giving one of three responses. Thankfully, the WHATWG maintains a table of browser responses so we can see which response for a given container format, or container and codec combination, we should get from a given browser: http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support. Microsoft has a small script demonstrating how this works here: http://msdn.microsoft.com/de-de/library/hh325437(v=vs.85).aspx.

Audio and Video Media Players to the Rescue

What a mess.

Fortunately, people have written tools to take the pain out of serving the right video (or audio) to the right browser. These media players hold your hand through the whole codecs mess and legacy support issues, provide plenty of customization options, and generally smooth out the whole implementation process.

Here are a few examples.

MediaElement (Video and Audio, Free)

http://mediaelementjs.com

This is a popular audio and video player that lets you use one file (an H.264 video file, for example) and deploy a consistent UI across all devices using Flash (or Silverlight) for playback where H.264 isn’t natively supported. It comes with a jQuery plug-in, as well as plug-ins for Drupal and WordPress. See figure 10-3 for an example.

9781430264156_Fig10-03.jpg

Figure 10-3. Mediaelement.js deploys a consistent UI across multiple playback codecs

VideoJS (Video, Free)

http://videojs.com

VideoJS (figure 10-4) is a slick HTML5 video player that offers some familiar CSS-based skins and similar broad support using Flash fallbacks for HTML5 video. It uses the markup from Video for Everyone (we provided the link to this earlier) and adds JavaScript for broader compatibility and CSS skinning options.

9781430264156_Fig10-04.jpg

Figure 10-4. VideoJS is another good framework for providing video with an Adobe Flash fallback

Flowplayer (Video, Free and Commercial)

http://flowplayer.org

Flowplayer (figure 10-5) is a free, open source player with Flowplayer branding. There’s also a commercial offering (with support option) without branding.

9781430264156_Fig10-05.jpg

Figure 10-5. Flowplayer is an open source player that has a supported commercial offering

More Media Players

There are a variety of other players out there, including the following:

(Of course, you can always use YouTube or Vimeo and let the native iOS playback take care of itself!)

With these available, there’s no need to roll your custom solution. Just grab one off the shelf and skin to your heart’s content.

Other Flies in the HTML5 Video Ointment: DRM, Streaming, and Full-Screen Video

We’ve got basic <video> and <audio> embedding down, but even with our handy, ready-to-go media players and their Flash fallbacks, there are still some significant missing (or very immature) features that HTML5 video lacks but Flash supports. As codecs continue to mature, there will be pressure on browser makers to support all of the important features of HTML5 video and audio sooner rather than later. When it comes to DRM, that may not be a good thing.

DRM

In February 2012, representatives from Google, Microsoft, and Netflix submitted the Encrypted Media Extensions v0.1 draft proposal (http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html) to the W3C’s HTML Working Group. The abstract for the proposal said this:

This proposal extends HTMLMediaElement to enable playback of protected content. The proposed API supports use cases ranging from simple clear key decryption to high value video (given an appropriate user agent implementation). License/key exchange is controlled by the application, facilitating the development of robust playback applications supporting a range of content decryption and protection technologies. No "DRM" is added to the HTML5 specification, and only simple clear key decryption is required as a common baseline.

That is, this would provide a mechanism for DRM to happen on top of HTML5, for both <audio> and <video>, by extending the JavaScript API (the HTMLMediaElement interface). The HTML5 editor, Ian Hickson, responded with the following (http://lists.w3.org/Archives/Public/public-html/2012Feb/0274.html):

I believe this proposal is unethical and that we should not pursue it.

Hickson also stated “DRM is evil” and then further elaborated on his reasons for rejecting the proposal outright here: https://www.w3.org/Bugs/Public/show_bug.cgi?id=10902#c24. Mozilla also expressed concerns, given that DRM and an open source browser are generally mutually exclusive (see this Ars Technica article for more: http://arstechnica.com/business/news/2012/02/unethical-html-video-copy-protection-proposal-criticized-by-standards-stakeholders.ars).

I mostly agree with Hickson. DRM is evil. Remember PlaysForSure? No? Exactly.

There is one important difference between DRM for video and DRM for audio, though, and that’s streaming. We have a culture of streaming (and renting) video, in a way that we didn’t with audio when the music DRM wars were raging. DRM sucked when it was applied to music you bought because if the DRM platform died (and they did), so did your music collection. The temporal nature of streaming media alleviates these concerns, but only to a point. (And if it can be implemented for streaming media, it’s not hard to imagine the media majors insisting on DRM for purchased content, too.)

These issues around streaming “protected” content explains Netflix’s interest in seeing some sort of DRM available when using web standards. Netflix was keen to use HTML5 (in the broad “web platform” sense) where it can (as it discusses here: http://techblog.netflix.com/2010/12/why-we-choose-html5-for-user.html), but Netflix obviously felt it needed some kind of DRM system in place to stream the content it licenses with HTML5. (They also need an actual streaming protocol, as we’ll see next.) Some at Google and Microsoft evidently feel this is a necessity too. (Note, though, that Hickson also works for Google, so it’s not a company-wide position.)

This may be another case where the post-Flash Web results not in an open standards utopia but in a return to platform-specific apps. That said, given the cost of implementing DRM, that may be a price the standards movement is willing to bear.

Debate raged on the W3C mailing lists, with a summary here: http://lists.w3.org/Archives/Public/public-html/2012Mar/0087.html.

But that debate may have always been moot. In March 2012, Philippe Le Hegaret from the W3C wrote the following (http://lists.w3.org/Archives/Public/public-html/2012Mar/0097.html):

[L]et's be clear: W3C has many participants interested in finding a solution around media content protection. So, we are definitively interested in the space, independently of whether the HTML Working Group is interested in developing a solution or whether it is done in a separate group. Whatever we choose, we will do our best to get the right balance between producers and consumers.

That is, we’re going to implement DRM with or without you because our paid-up members want it. Ominous stuff.

By late 2013 it appears the fight against DRM is over, and DRM won.

First, the Encrypted Media Extensions proposal is in full working draft. It was first publically released in May 2013 with much controversy (www.w3.org/blog/2013/05/perspectives-on-encrypted-medi/), particularly from the Free Software Foundation (you can read the recommendation against EME here: www.fsf.org/news/coalition-against-drm-in-html). The editor’s draft can be found here: https://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html.

Second and more importantly, Chrome and IE11 already support EME. As everyone should remember by now, the browser makers make the rules. Without them, the spec is a work of fiction. Despite the controversy, it appears like this fight is over, and DRM won this round. It’s unlikely to make it into the final W3C spec by 2014 since it’s not in revision status yet, but once the browsers are on board, the spec is just a formality.

Third, Netflix is streaming over HTML5 in some cases, using EME. As of late 2013 it’s not its mainstream distribution channel, but it’s available. Netflix has been a big supporter of EME. When you have browser support and major corporations already using DRM in HTML5, it’s hard to imagine a universe in which the spec and other browsers don’t get on board very quickly.

Streaming

For a long time, streaming video over HTML5 was one of the largest challenges to moving off of Flash. Flash provided a very stable streaming media solution for decades and was the entrenched solution of choice, and the HTML5 spec wasn’t quick in coming up with a better alternative. Ars Technica summed it up well in 2011 through an excellent article titled “The trials and tribulations of HTML video in the post-Flash era” (http://arstechnica.com/business/news/2011/11/the-trials-and-tribulations-of-html-video-in-the-post-flash-era.ars):

[T]ransitioning video delivery in the browser from Flash to HTML5 will also pose some major challenges for content creators. The standards aren’t fully mature yet and there are still a number of features that aren’t supported or widely available across browsers.

For an illustration of how deep the problems run, you need only look at Mozilla’s Firefox Live promotional website, which touts the organization’s commitment to the open Web and shows live streaming videos of Red Panda cubs from the Knoxville Zoo. The video is streamed with Flash instead of using standards-based open Web technologies.

In an FAQ attached to the site, Mozilla says that it simply couldn’t find a high-volume live streaming solution based on open codecs and open standards. If Mozilla can’t figure out how to stream its cuddly mascot with open standards, it means there is still work to do.

A streaming standard has been in the works for some time, called Dynamic Adaptive Streaming over HTTP (DASH), which has the support of Microsoft , the BBC, and others, but there’s still a way to go there before support materializes. DASH is also codec agnostic—it doesn’t resolve the codec impasse we discussed earlier. (For more, see “What is MPEG DASH?”: www.streamingmedia.com/Articles/ReadArticle.aspx?ArticleID=79041.)

Apple currently has its own streaming protocol, HTTP Live Streaming (HLS), which is used to deliver content to its iOS devices. Google added support in Android 3.0+, and it allows encrypted data and works with third-party DRM solutions. See “What is HLS (HTTP Live Streaming)?” for more: www.streamingmedia.com/Articles/Editorial/What-Is-…/What-is-HLS-%28HTTPLive-Streaming%29-78221.aspx.

Regardless of what protocol one uses to stream, by late 2013 the W3C is in working draft for the Media Source Extensions (MSE) API, which allows a page to define support for media streams through JavaScript (www.w3.org/TR/media-source/). The spec currently supports several different types of streams and the ability to define additional through JavaScript libraries (like DASH through dash.js). The major players are all planning to support it. Once MSE is in place and fully supported, then streaming is solved, and the provider must simply provide any necessary JavaScript libraries to translate the stream and send the data in a codec supported by the browser to provide real streaming video. IE11 and Chrome already support it, which is how Netflix can stream in HTML5 through extensions on those browsers.

Fullscreen API

Finally, one of the most common things we do with Flash video is make it full-screen. This wasn’t possible in HTML5 until recently, when the Fullscreen API spec moved ahead in the W3C (http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html). All of the major desktop browsers are moving ahead in anticipation of the spec. Mobile browsers aren’t on board yet, but most of them go full-screen for all video elements by default anyway. Interestingly, the Fullscreen API can make any element full-screen, including (for example) the <canvas> element, and it could be used for a full-screen reading mode too, for example.

For more on the Fullscreen API, see the following:

Is HTML5 <audio> Ready for Games?

One final note on <audio> and its potential for gaming.

Dominic Szablewski posted an epic (and profanity-laced!) rant on the state of HTML5 audio, in relation to developing HTML5 games. It’s well worth a read for entertainment value and gives some indication of the (im)maturity of HTML5 audio support, particularly for interactive purposes. Szablewski says this:

Surprisingly, Google's Chrome has the worst HTML5 Audio support of all the good Desktop Browsers - that is every Browser but IE. I'm not an audio engineer, but before Browser vendors took their shot at it, my impression of digital audio was that it is a solved problem. I'm amazed that after so many iterations HTML5 Audio is still that broken.

The Audio support on mobile Browsers (iOS and Android) is laughable at best. It's completely unusable for even the simplest of tasks. You can jump through hoops and ask real nice, but it still sucks ass.

(See the article for more: www.phoboslab.org/log/2011/03/the-state-of-html5-audio. I love the Scumbag Steve hat.)

In 2013 the story is mostly still the same. WebAudio is almost ready, the codecs seem to be coalescing, but game developers still run into problems. In late 2013 the game development blog Indiegamr summed it up this way in a post titled “The State of Audio in HTML5 Games” (http://indiegamr.com/the-state-of-audio-in-html5-games/):

…there is no single codec and format that is supported by all browsers and devices. In addition to this not every device does support the WebAudio-API and some devices only allow audio-playback upon a user-interaction or only allow playing one sound at a time. So what should you do? Setup an audio file for any codec and then check the browser’s support before loading and playing the file? While this would be currently the only way to do it right, this not only sounds like a lot of work, but also is. What about browsers that don’t support the audio-element at all? – Implementing a flash fallback is no easy task as well.

The short answer? No, it’s not really ready for games.

In the meantime, cross-platform libraries, perhaps with Flash fallbacks built in, are required to get the job done. Here’s a short list of libraries to look into:

  • SoundJS, part of the CreateJS suite championed by Adobe, Microsoft, and AOL, provides a Flash fallback and handles cross-browser issues gracefully: www.createjs.com/#!/SoundJS.
  • The HowlerJS framework is open source and freely available under the MIT license. It has no Flash fallback, so it won’t support older browsers easily: https://github.com/goldfire/howler.js/.
  • SoundManager has long been the standard of JavaScript audio. It provides a Flash fallback if required: www.schillmania.com/projects/soundmanager2/.

Until IE and others get on board with the WebAudio API, we’re stuck with hiding Flash in the background to serve audio. Welcome to the modern Web.

Wrapping Up

Native support for <audio> and <video> is welcome and necessary for mobile devices in particular. But keep in mind that the technology is still somewhat immature (especially on Android).

The codec issues will not be resolved any time soon, and iOS will still need H.264 for video. So, we need to tread carefully. Don’t assume it will work flawlessly just because it’s in the spec.

At the time of this writing, we’ve come a long way. Just a few years ago the codecs were completely fractured and the spec still totally up in the air on basic things such as full-screen video or whether an audio API would ever be included, let alone controversial topics such as DRM. Yet today we have all three included in the working spec, and a majority of the browsers are on board. The codec wars feel like they’re winding down, despite Mozilla’s push for Opus in audio, and it seems like stability is just around the corner.

But we’re not there yet. Until every major browser supports a small set of codecs (let alone a single one) for audio and video, a single API for audio, and consistent streaming and DRM capabilities, audio and video will remain difficult areas for developers. Commitment to the open Web means supporting multiple ways of doing everything. JavaScript frameworks provide some help, and we’re still stuck with legacy support through Flash for a good while regardless.

My advice? Find a few good components that do the heavy lifting. Then, keep an eye on what your favorite media player supports, and let it be your guide for which technologies to bet on in the future.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.247.68