Your SlideShare is downloading. ×
  • Like
audio, video and canvas in HTML5 - standards>next Manchester 29.09.2010
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

audio, video and canvas in HTML5 - standards>next Manchester 29.09.2010

  • 4,066 views
Published

Part II of the standards-next.org workshop on HTML5 with Bruce Lawson, concentrating on audio, video and canvas (plus hints of additional HTML5 API niceness)

Part II of the standards-next.org workshop on HTML5 with Bruce Lawson, concentrating on audio, video and canvas (plus hints of additional HTML5 API niceness)

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,066
On SlideShare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
87
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. audio, video and canvas in HTML5 NATIVE MULTIMEDIA SUPPORT Patrick H. Lauke / standards>next / Manchester / 29 September 2010
  • 2. HTML5 <!DOCTYPE html>
  • 3. “...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 HTML5 http://lists.w3.org/Archives/Public/public-html/2009Jan/0215.html
  • 4. making your site Fonzie compliant...
  • 5. <video>
  • 6. Adobe Flash currently most common video delivery mechanism
  • 7. <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&f s=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed> </object>
  • 8. <video src="video.webm" controls Autoplay Loop preload="none" poster="poster.jpg" width="320" height="240"> <a href="video.webm">Download movie</a> </video>
  • 9. video as native object ● “plays nice” with rest of the page ● keyboard accessibility built-in
  • 10. video formats the big debate
  • 11. MP4 / H.264 ubiquitous, patent encumbered, licensing/royalties
  • 12. Ogg Theora “free and open”, no licensing/royalties not many tools for it, not web optimised
  • 13. www.webmproject.org
  • 14. WebM open and royalty-free, web optimised
  • 15. www.youtube.com/html5
  • 16. 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>
  • 17. still include fallback for old browsers http://camendesign.com/code/video_for_everybody
  • 18. <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>
  • 19. powerful (simple) API to script your own controls
  • 20. icant.co.uk/easy-youtube
  • 21. www.w3.org/TR/html5/video.html#media-elements
  • 22. controlling a <video> element var v = document.getElementById('player'); v.play(); v.pause(); v.volume = … ; v.currentTime = … ; …
  • 23. 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) …
  • 24. <audio>
  • 25. 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)
  • 26. <canvas>
  • 27. canvas = “scriptable images” <canvas width="…" height="…"></canvas>
  • 28. canvas has standard API methods for drawing ctx = canvas.getContext("2d"); ctx.fillRect(x, y, width, height); ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x, y); ctx.bezierCurveTo(x1, y1, x2, y2, c1, c2);
  • 29. canvas drawing ready-made images ctx = canvas.getContext("2d"); var logo = new Image(); logo.src = 'logo.png'; ctx.drawImage(logo,x1,y1,w1,h1,x2,y2,w2,h2); or call in an existing image already on the page
  • 30. canvas access to image data array ctx = canvas.getContext("2d"); canvasData = ctx.getImageData(x,y,w,h); [R,G,B,A,R,G,B,A,R,G,B,A,R,G,B,A, … ]
  • 31. canvas exporting image data as data:uri ctx = canvas.getContext("2d"); … canvas.toDataURL("image/png"); // returns "data:image/png;base64,…" canvas.toDataURL("image/jpg"); // returns "data:image/jpeg;base64,…" Note: do it on the canvas, not the context!
  • 32. canvas also works with video ctx = canvas.getContext("2d"); v = document.getElementById('player'); ctx.drawImage(v,x1,y1,w1,h2,x2,y2,w2,h2); grab currently displayed frame (update as appropriate)
  • 33. canvas accessibility concerns
  • 34. video, audio and canvas on any device without plugins (Java / Flash / Silverlight not ubiquitous)
  • 35. HTML5 (and friends) has lots more APIs for developers (for powerful client-side apps)
  • 36. isgeolocationpartofhtml5.com
  • 37. geolocation navigator.geolocation.getCurrentPosition(success, error); navigator.geolocation.watchCurrentPosition(success, error); function success(position) { /* where's Wally? */ var lat = position.coords.latitude; var long = position.coords.longitude; ... }
  • 38. offline detection... window.addEventListener('online', function(){ … }, true); window.addEventListener('offline', function(){ … }, true); and application cache <html manifest=”blah.manifest”> CACHE MANIFEST # send this with correct text/cache-manifest MIME images/sprites.png scripts/common.js scripts/jquery.js styles/global.css data.xml and many more... (even beyond HTML5)
  • 39. is it all safe to use, right now?
  • 40. don't do browser sniffing http://www.flickr.com/photos/timdorr/2096272747/
  • 41. feature-detection progressive enhancement, graceful degradation – or use shims http://diveintohtml5.org/everything.html
  • 42. feature-detection for audio/video if (!!document.createElement('video').canPlayType;) { … } if (!!document.createElement('audio').canPlayType;) { … }
  • 43. 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'))) { … }
  • 44. ready-made HTML5 audio/video players (for the lazy)
  • 45. sublimevideo.net
  • 46. videojs.com
  • 47. www.happyworm.com/jquery/jplayer
  • 48. HTML5 as Flashkiller?
  • 49. not a question of HTML5 replacing Flash...
  • 50. giving developers a choice!
  • 51. www.opera.com/developer people.opera.com/patrickl/presentations/standards-next_29.09.2010/standards-next_29.09.2010.pdf patrick.lauke@opera.com