audio and video in html5 - london web standards 20.09.2010

42
Audio and Video in HTML5 Patrick H. Lauke / London Web Standards / London / 20 September 2010 NATIVE MULTIMEDIA SUPPORT

Upload: patrick-lauke

Post on 15-May-2015

2.671 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Audio and Video in HTML5 - London Web Standards 20.09.2010

Audio and Video in HTML5

Patrick H. Lauke / London Web Standards / London / 20 September 2010

NATIVE MULTIMEDIA SUPPORT

Page 2: Audio and Video in HTML5 - London Web Standards 20.09.2010

HTML5<!DOCTYPE html>

Page 3: Audio and Video in HTML5 - London Web Standards 20.09.2010

“...extending the language to better support Web applications [...] This puts HTML in direct competition with other technologies[...] , in particular Flash and Silverlight.”

Ian Hickson, Editor of HTML5http://lists.w3.org/Archives/Public/public-html/2009Jan/0215.html

Page 4: Audio and Video in HTML5 - London Web Standards 20.09.2010

<video>

Page 5: Audio and Video in HTML5 - London Web Standards 20.09.2010

Adobe Flash currently most commonvideo delivery mechanism

Page 6: Audio and Video in HTML5 - London Web Standards 20.09.2010

<object width="425" height="344"><param name="movie"

value="http://www.youtube.com/v/9sEI1AUFJKw&hl=en&fs=1&"></param>

<param name="allowFullScreen" value="true"></param>

<param name="allowscriptaccess" value="always"></param>

<embed src="http://www.youtube.com/v/9sEI1AUFJKw&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>

Page 8: Audio and Video in HTML5 - London Web Standards 20.09.2010

<video src="video.webm" controls autoplay poster="poster.jpg" width="320" height="240"> <a href="video.webm">Download movie</a></video>

Page 9: Audio and Video in HTML5 - London Web Standards 20.09.2010

video as native object● “plays nice” with rest of the page● keyboard accessibility built-in

Demonstration of basic video, keyboard access, hover/transitions

Page 10: Audio and Video in HTML5 - London Web Standards 20.09.2010

video formatsthe big debate

Page 11: Audio and Video in HTML5 - London Web Standards 20.09.2010

MP4 / H.264

ubiquitous, patent encumbered, licensing/royalties

Page 12: Audio and Video in HTML5 - London Web Standards 20.09.2010

Ogg Theora

“free and open”, no licensing/royaltiesnot many tools for it, not web optimised

Page 13: Audio and Video in HTML5 - London Web Standards 20.09.2010

www.webmproject.org

Page 14: Audio and Video in HTML5 - London Web Standards 20.09.2010

WebM

open and royalty-free, web optimised

Page 15: Audio and Video in HTML5 - London Web Standards 20.09.2010
Page 16: Audio and Video in HTML5 - London Web Standards 20.09.2010

www.youtube.com/html5

Page 17: Audio and Video in HTML5 - London Web Standards 20.09.2010

providing multiple sources<video controls autoplay poster="…" width="…" height="…">

<source src="movie.webm" type="video/webm" /><source src="movie.ogv" type="video/ogg" /><source src="movie.mp4" type="video/mp4" /><!-- fallback content -->

</video>

Page 18: Audio and Video in HTML5 - London Web Standards 20.09.2010

still include fallback for old browsershttp://camendesign.com/code/video_for_everybody

Page 19: Audio and Video in HTML5 - London Web Standards 20.09.2010

<video controls autoplay poster="…" width="…" height="…"><source src="movie.webm" type="video/webm" /><source src="movie.ogv" type="video/ogg" /><source src="movie.mp4" type="video/mp4" /><object width="…" height="…" type="application/x-

shockwave-flash" data="player.swf"><param name="movie" value="player.swf" /><param name="flashvars" value=" … file=movie.mp4" /><!-- fallback content -->

</object></video>

Page 20: Audio and Video in HTML5 - London Web Standards 20.09.2010

powerful (simple) APIto script your own controls

Page 21: Audio and Video in HTML5 - London Web Standards 20.09.2010

icant.co.uk/easy-youtube

Page 22: Audio and Video in HTML5 - London Web Standards 20.09.2010

www.w3.org/TR/html5/video.html#media-elements

Page 23: Audio and Video in HTML5 - London Web Standards 20.09.2010

controlling a <video> element

var v = document.getElementById('player');

v.play();v.pause();v.volume = … ;v.currentTime = … ;…

Page 24: Audio and Video in HTML5 - London Web Standards 20.09.2010

events fired by <video> element

var v = document.getElementById('player');v.addEventListener('loadeddata', function() { … }, true)v.addEventListener('play', function() { … }, true)v.addEventListener('pause', function() { … }, true)v.addEventListener('timeupdate', function() { … }, true)v.addEventListener('ended', function() { … }, true)…Demonstration of basic and advanced video controls, swapping sources

Page 25: Audio and Video in HTML5 - London Web Standards 20.09.2010

people.opera.com/philipj/2010/07/21/html5-video-webinar/demos/track.html

Page 26: Audio and Video in HTML5 - London Web Standards 20.09.2010

<audio>

Page 27: Audio and Video in HTML5 - London Web Standards 20.09.2010

audio exactly the same as video

<audio src=”music.mp3” controls autoplay></audio>[...]<audio controls autoplay>

<source src="music.mp3" type="audio/mpeg" /><source src="music.oga" type="audio/ogg" /><!-- fallback content -->

</audio>

same format debacle: MP3 vs Ogg Vorbis (vs WAV)

Demonstration of basic audio, scripted audio, note about controls

Page 28: Audio and Video in HTML5 - London Web Standards 20.09.2010

video and audio on any devicewithout plugins

(Java / Flash / Silverlight not ubiquitous)

Page 29: Audio and Video in HTML5 - London Web Standards 20.09.2010
Page 30: Audio and Video in HTML5 - London Web Standards 20.09.2010

is it all safe to use, right now?

Page 31: Audio and Video in HTML5 - London Web Standards 20.09.2010

don't do browser sniffing

http://www.flickr.com/photos/timdorr/2096272747/

Page 32: Audio and Video in HTML5 - London Web Standards 20.09.2010
Page 33: Audio and Video in HTML5 - London Web Standards 20.09.2010

feature-detection for audio/video

if (!!document.createElement('video').canPlayType;) { … }if (!!document.createElement('audio').canPlayType;) { … }

Page 34: Audio and Video in HTML5 - London Web Standards 20.09.2010

feature-detection for audio/video codecs

var v = document.createElement('video');if (!!(v.canPlayType)&& ((v.canPlayType('video/webm;codecs="vp8,vorbis"') == 'probably') || (v.canPlayType('video/webm;codecs="vp8, vorbis"') == 'maybe'))) { … }

Page 35: Audio and Video in HTML5 - London Web Standards 20.09.2010

feature-detectionprogressive enhancement, graceful degradation – or use shims

http://diveintohtml5.org/everything.html

Page 36: Audio and Video in HTML5 - London Web Standards 20.09.2010

ready-made HTML5 audio/video players(for the lazy)

Page 37: Audio and Video in HTML5 - London Web Standards 20.09.2010

sublimevideo.net

Page 38: Audio and Video in HTML5 - London Web Standards 20.09.2010

videojs.com

Page 39: Audio and Video in HTML5 - London Web Standards 20.09.2010

HTML5 as Flashkiller?

Page 40: Audio and Video in HTML5 - London Web Standards 20.09.2010

not a question of HTML5 replacing Flash...

Page 41: Audio and Video in HTML5 - London Web Standards 20.09.2010

giving developers a choice!

Page 42: Audio and Video in HTML5 - London Web Standards 20.09.2010

www.opera.com/developerpeople.opera.com/patrickl/presentations/lws_20.09.2010/lws_20.09.2010.pdf

[email protected]