HTML5 Doctor » source http://html5doctor.com helping you implement HTML5 today Wed, 02 Mar 2016 08:08:54 +0000 en-US hourly 1 Review: HTML5 Multimedia: Develop and Design https://stevefaulkner.github.io/html5doctored/review-html5-multimedia-develop-and-design/ https://stevefaulkner.github.io/html5doctored/review-html5-multimedia-develop-and-design/#comments Tue, 28 Aug 2012 17:03:18 +0000 http://html5doctor.com/?p=4744

Related Posts:

]]>
With a number of HTML5 books now available, we’re starting to see them cover more specific areas of HTML5. HTML5 Multimedia: Develop and Design, written by fellow HTML5 Doctor Ian Devlin, focusses on native multimedia in HTML5. Read my review below to find out what it’s all about.

Disclosure: Ian is a friend of mine (though I’ve never met him in real life, so I can’t actually confirm he exists), an HTML5 Doctor, and a fellow curator of HTML5 Gallery. This review isn’t biased though.

It’s an honest opinion of the book.

I’ve been meaning to write this review since the book came out — and before Ian joined the surgeons on this site — but I didn’t get around to it. Thankfully much of the book is still relevant.

Although Ian’s book is primarily about HTML5 multimedia, he actually covers much more, including brief introductions to new HTML5 elements, parts of CSS3, canvas, SVG, and WebSockets whilst linking them all back to native multimedia. It’s a comfortable length, easy to read, has solid examples, and dives into lots of detail in places. There’s useful, practical information regarding such things as MIME types and MP4 profiles and other gotchas that you don’t always see in other books and articles. And the best thing: Ian has tested all this himself and not relied on someone else’s word.

Cover of HTML5 Multimedia: Develop and Design Book

HTML5 Multimedia: Develop and Design, by Ian Devlin

The book starts with an introduction to HTML5, including a potted history and some detail about many of the new elements. You can probably skip this chapter if you know a bit about HTML5.

The second chapter is dedicated to the history of web-based multimedia. Ian manages to tell the story in detail without making it boring. I found the web multimedia history lesson very interesting as it reminded me of the pains we endured making sites in the early days of the web. This chapter also introduces the four main multimedia elements (<audio>, <video>, <source>, and <track>) covered in the book, along with their associated attributes.

Chapters 3 and 4 cover <audio> and <video> and their attributes in further detail. It’s well-written and easy to understand with good humour expressed throughout the examples. Ian does perhaps gloss over some of the downsides, such as having to encode and host files multiple times, particularly for commercial sites (although it is mentioned in passing in Chapter 4). This is understandable, though, as native multimedia is still overall a big win for developers and users.

For video in particular, there’s good coverage of media queries and media types and even caveats for Android (or targeting other devices and serving appropriate content). Ian also includes a helpful tip about qtindexswapper that you may have seen in Ian’s recent Multimedia Troubleshooting article.

The next chapter covers the media API. It’s a simple and easy-to-follow introduction for someone (like me) who doesn’t write a lot of JavaScript. Ian shows how to script your own controls, amongst other things. It would’ve been nice to see complete code examples at the end of each section, so you could see exactly where each portion of the script fits in relation to the others.

Chapters 6 and 7 cover styling with CSS. If you’re up to speed with CSS3, then you should find it all simple enough. There’s all your standard rounded corners, gradients, and shadow shizzle included. The object properties and transitions and animation are also covered, which are good to know about.

I do have to question the value of these chapters for readers. Perhaps it’s beneficial for those with little knowledge of CSS, but overall these chapters feel too long and take up a large portion of content that could have been used to explore the API or accessibility (“a11y”) in more detail.

Speaking of a11y, that’s covered in Chapter 8. It includes a thorough introduction to WebVTT, the <track> element, and keyboard interaction. I would have liked to see Ian dig a little deeper and look at other a11y areas that are appropriate to multimedia.

Ian then looks at using video with canvas and SVG. He includes some useful ideas such as taking a screenshot using canvas or grey-scaling a video. For SVG, there are some excellent tips about masking and animating masks over video using SVG shapes (plus a brief intro to SVG for those who haven’t used it). He introduces SVG filters, but it was unclear to me how I link the SVG filters to the actual video files. Again, I think complete final examples would have been good to see here.

The book closes with a useful overview of where native multimedia is heading and introduces a number of new APIs coming soon (or already here in some cases) to a browser near you.

Summary

In summary, the book is easy to read and has an appropriate level of detail throughout with good examples to supplement the explanation. I’d definitely recommend this book to anyone who’s looking to do more with HTML5 Multimedia than simply add it to a site as you see in a lot of tutorials.

Review: HTML5 Multimedia: Develop and Design originally appeared on HTML5 Doctor on August 28, 2012.

]]>
https://stevefaulkner.github.io/html5doctored/review-html5-multimedia-develop-and-design/feed/ 3
Native Audio in the browser https://stevefaulkner.github.io/html5doctored/native-audio-in-the-browser/ https://stevefaulkner.github.io/html5doctored/native-audio-in-the-browser/#comments Wed, 29 Jul 2009 15:00:29 +0000 http://html5doctor.com/?p=497

Related Posts:

]]>
Until recently, the ability to play any type of audio within a browser involved using Adobe Flash or other browser plugins. Although Adobe's Flash player is unquestionably the most ubiquitous of these, most developers and designers would agree that it's better not to rely on a plugin at all.

Enter HTML5 <audio>

One of the most exciting and long-awaited features in HTML5 the <audio> element, enabling native audio playback within the browser. We can take advantage of this now as all of the major browsers support it — currently Firefox, Chrome, Safari and Opera, and Internet Explorer 9+. For browsers that don't support audio natively, we can easily fallback to Flash.

According to spec

Currently, the HTML5 spec defines five attributes for the <audio> element:

  1. src — a valid <abbr>URL</abbr> specifying the content source
  2. autoplay — a boolean specifying whether the file should play as soon as it can
  3. loop — a boolean specifying whether the file should be repeatedly played.
  4. controls — a boolean specifying whether the browser should display its default media controls
  5. preload — none / metadata / auto — where 'metadata' means preload just the metadata and 'auto' leaves the browser to decide whether to preload the whole file.

Incidentally these are the same attributes defined for the <video> element.

Examples

Let's take a couple of these attributes and create a simple example that will play an audio file:

<audio src="elvis.ogg" controls preload="auto"></audio>

(This example will work for the latest versions of Firefox, Chrome and Opera. You'll need to replace the Ogg file with an MP3 to get it working in Safari and Internet Explorer 9+.)

For a list of which codecs are supported on which browser (which may differ depending on device) see our article HTML5 Audio — The State of Play.

To create our own controls, we can use the API methods defined by the spec:

  • play() — plays the audio
  • pause() — pauses the audio
  • canPlayType() — interrogates the browser to establish whether the given mime type can be played
  • buffered() — attribute that specifies the start and end time of the buffered part of the file

Use the Source

The best way to coerce browsers into playing audio (or video, for that matter) is to use the <source> element. The browser will try to load the first audio source, and if it fails or isn't supported, it will move on to the next audio source. In addition, we can embed a Flash player if all else fails:

<audio controls preload="auto"> 
  <source src="elvis.mp3" />
  <source src="elvis.ogg" />
  <!-- now include flash fall back -->
</audio>

One caveat, though: you may need to be careful about the order of the <source> elements. At the time of going to press issues have been reported with older versions of Firefox and Mobile Safari.

Cross-Browser Implementation

When we created jPlayer, an audio player plugin for jQuery, we were attempting to address some of the limitations of the current crop of Flash-based audio players. Many relied on Flash to implement the player's graphical interface, effectively isolating the player from the rest of the web design process.

The original jPlayer relied on Flash to play the actual audio while allowing the look and feel to be styled via HTML and CSS. With growing support for HTML5 in modern browsers, we were inspired to break our Flash dependency and use native audio when it was supported.

The most significant issue is the cross-browser implementation, where lack of a common supported audio format among browsers causes complications. If developers want to take full advantage of all browsers that support HTML5 audio, they'll need to create both MP3 and Ogg versions of the audio file they want to stream!

JavaScript solutions

If we intend to take advantage of each browser's audio capabilities, we need to create different solutions for different browsers. We could use browser sniffing, but considering the rapidly changing landscape, it's better to check what capabilities a particular browser supports and adapt accordingly.

To demonstrate this "feature sniffing", we've created a rough and ready HTML5 audio checker.

Using JavaScript, you can check for audio tag support:

// returns a boolean
var audioTagSupport = !!(document.createElement('audio').canPlayType);

or check file type compatibility:

// Need to check the canPlayType first or an exception
    // will be thrown for those browsers that don't support it      

    var myAudio = document.createElement('audio'); 
    
    if (myAudio.canPlayType) {
      
       // Currently canPlayType(type) returns: "", "maybe" or "probably" 

       var canPlayMp3 = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/mpeg');
       var canPlayOgg = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/ogg; codecs="vorbis"');
    }

Note that to change the src attribute of an audio object or element, you'll need to recreate the object or element with the new value for its src attribute or alternatively change the src URL and then issue a myAudio.load() command.

So, to create a solution that takes full advantage of HTML5 audio, you'll typically need to:

  1. check for HTML5 audio support, and if not present, fall back on Flash,
  2. check the level of HTML5 audio support and adapt your code accordingly for each browser, and
  3. check what file types are supported and link to appropriate formats of the files.

The Road Ahead

Although HTML5 audio is a relatively immature part of the standard, if recent trends continue and users upgrade to the latest versions of Safari, Firefox, Chrome and Opera, browser support is likely above 30% today. This is a significant chunk of the browser market that will no longer need to rely on Adobe's Flash, Microsoft's Silverlight, or any other browser plugin for audio support. Add to this the fact that Internet Explorer 9 supports HTML5 audio and we could easily see the majority of installed browsers supporting it in the very near future.

And when you consider that mobile and other lower-spec devices such as tablets are choosing to support HTML5 audio, you begin to paint a picture of how important native audio support is becoming.

Further reading:

Native Audio in the browser originally appeared on HTML5 Doctor on July 29, 2009.

]]>
https://stevefaulkner.github.io/html5doctored/native-audio-in-the-browser/feed/ 163