105
4/16/13 HTML5 at YouTube: Stories from the Front Line gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 1/105

Html5 at YouTube: Stories from the Front Line

Embed Size (px)

DESCRIPTION

This is the PDF version. The HTML5 awesome version is at http://gregthebusker.com/html5/html5_at_youtube_u_of_i.html Is HTML5 ready for production code? Of course it is. This is a look into all the different HTML5 technologies we use in live code at YouTube. We'll have a collection of tips, tricks, and best practices for HTML5 video, the track tag, getUserMedia, and more. Plus a deep dive into Mobile Video Tag development.

Citation preview

Page 1: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 1/105

Page 2: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 2/105

#HTML5Video

HTML5 at YouTube: Stories from

the Front LineGreg Schechter - Web Warrior, Facebook

2/105

Page 3: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 3/105

Greg SchechterThe Web Warrior

[email protected]

#HTML5Video 3/105

Page 4: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 4/105

What are conferences allabout?

Page 5: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 5/105

Page 6: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 6/105

I R one C00LZ Kat

http://www.flickr.com/photos/scjn/4564274827/

Page 7: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 7/105

Last year's coolness

#HTML5Video 7/105

Page 8: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 8/105

This year's awesome hardware

#HTML5Video 8/105

Page 9: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 9/105

Put them together

#HTML5Video 9/105

Page 10: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 10/105

Put them together

#HTML5Video 10/105

Page 11: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 11/105

Is the coolness ready to use?

Page 12: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 12/105

I's ready for battlez

http://www.flickr.com/photos/mycoolpics/92033686/

Page 13: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 13/105

http://www.w3.org/html/logo/

Page 14: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 14/105

#HTML5Video

Graphics Connectivity CSS3 Styling Device Access

Multimedia Offline and

Storage Performance

and Integration Semantics

14/105

Page 15: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 15/105

Who can use this stuff?

Page 16: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 16/105

Depends on your users

Page 17: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 17/105

What users I prioritize development for

Chrome

Firefox

Safari Opera

IE

Page 18: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 18/105

Why HTML5?

Page 19: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 19/105

CSS3 Styling

http://www.flickr.com/photos/dannykboyd/5048495262/

Page 20: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 20/105

Rounded Corners

With awesomeness

Without awesomeness

#HTML5Video

<style>

.somebox {

border-radius: 3px;

}

</style>

CSS

20/105

Page 21: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 21/105

Transitions

With Awesomeness

Awesome Information

Without Awesomeness

Awesome Information

#HTML5Video

<style>

.somebox {

-webkit-transition: height 1s, opacity 1s 1s;

-moz-transition: height 1s, opacity 1s 1s;

-ms-transition: height 1s, opacity 1s 1s;

-o-transition: height 1s, opacity 1s 1s;

transition: height 1, opacity 1s 1s;

}

</style>

CSS

21/105

Page 22: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 22/105

What CSS3 gets us

#HTML5Video

Enhance the user experience

Less code

Faster preformance

Less wasted development time and less hacks

The experience without it is still good

·

·

·

·

·

22/105

Page 23: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 23/105

Why HTML5?

Page 24: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 24/105

When HTML5?

Page 25: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 25/105

Who can use the css3 coolness.

Chrome

Firefox

Safari Opera

IE

Page 26: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 26/105

Performance &Integration

http://www.flickr.com/photos/dannykboyd/5048495262/

Page 27: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 27/105

Let's talk Uploads

Page 28: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 28/105

Page 29: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 29/105

XHR Uploads

#HTML5Video

<script>

function upload(blobOrFile) {

var xhr = new XMLHttpRequest();

xhr.open('POST', '/server', true);

xhr.onload = function(e) { ... };

// Listen to the upload progress.

var progressBar = document.querySelector('progress');

xhr.upload.onprogress = function(e) {

if (e.lengthComputable) {

progressBar.value = (e.loaded / e.total) * 100;

progressBar.textContent = progressBar.value; // Fallback for unsupported browsers.

}

};

xhr.send(blobOrFile);

}

</script>

JAVASCRIPT

29/105

Page 30: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 30/105

XHR Uploads

OldnessUpload progress

NewnessUpload progress

#HTML5Video 30/105

Page 31: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 31/105

Why is XHR Uploads an improvement

#HTML5Video

Richer user experience with progress updates

Multiple file uploads

Resumable uploads

No plugin required for advanced features

·

·

·

·

31/105

Page 32: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 32/105

Who can use the XHR upload coolness.

Chrome

Firefox

Safari Opera

IE

Page 33: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 33/105

Time to up the coolness

http://www.flickr.com/photos/tjc/4320473610/

Page 34: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 34/105

Multimedia

http://www.flickr.com/photos/dannykboyd/5048495262/

Page 35: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 35/105

#HTML5Video

video

35/105

Page 36: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 36/105

<video> expectations

#HTML5Video

Open source technology

Lower latency

Better performance and fidelity

Accessibility

Power Consumption*

·

Browser / Player / Codec-

·

No plug-in instantiation-

·

·

·

36/105

Page 37: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 37/105

HTML5 Video Capable Browsers

#HTML5Video

Chrome

Firefox

Safari Opera

IE

37/105

Page 38: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 38/105

Flash Support vs. HTML5 Support

Page 39: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 39/105

YouTube Data API Usage for Flash vs. HTML5Devices

Page 40: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 40/105

Let's talk mobile

http://www.flickr.com/photos/indi/2579412663/

Page 41: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 41/105

Why is Mobile Important

#HTML5Video 41/105

Page 42: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 42/105

Playback Stats

#HTML5Video

Mobile

Desktop

2010 2011 20120

1,500

3,000

4,500

6,000

Year

Pla

yba

ck in

Mill

ion

s

42/105

Page 43: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 43/105

#HTML5Video 43/105

Page 44: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 44/105

#HTML5Video 44/105

Page 45: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 45/105

#HTML5Video 45/105

Page 46: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 46/105

#HTML5Video 46/105

Page 47: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 47/105

Native

#HTML5Video

For fallbacks, use rtsp:// protocol (serving .3gp) if the device won't supportHTML5

Use custom protocol / URL scheme to launch the native app (on Android / BB:vnd.youtube:video_id)

iOS special-cases the YouTube Flash embed code

·

·

·

47/105

Page 48: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 48/105

#HTML5Video 48/105

Page 49: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 49/105

The Different Browsers

#HTML5Video 49/105

Page 50: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 50/105

The Different Browsers

#HTML5Video 50/105

Page 51: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 51/105

The Different Browsers

#HTML5Video 51/105

Page 52: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 52/105

#HTML5Video

http://www.flickr.com/photos/brownpau/533267369/

52/105

Page 53: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 53/105

How do we start?

#HTML5Video

<video>

53/105

Page 54: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 54/105

The Source

#HTML5Video

<video src="funny_cat_video">

54/105

Page 55: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 55/105

The Source

#HTML5Video

<video src="funny_cat_video.webm/mp4/ogg">

55/105

Page 56: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 56/105

Mobile Formats Support

#HTML5Video

Chrome Safari Firefox Opera IE Android

H264 Android 4.1+

WebM Android 4+ Android 4+ Android 4+

HLS Android 3+

56/105

Page 57: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 57/105

Platform Versions and Distribution

#HTML5Video 57/105

Page 58: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 58/105

The Source

#HTML5Video

<video>

<source src="funny_cat_video.mp4">

<source src="funny_cat_video.webm">

</video>

HTML

58/105

Page 59: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 59/105

Power

Page 60: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 60/105

Playback Stats

#HTML5Video

Software

Hardware

700 800 900 1,000 1,100

idle

webm

h264

flash

Mean current draw (milliamps)

Research done by Yossi Oren For more information visit http://iss.oy.ne.ro/

60/105

Page 61: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 61/105

Stick it in the page

Page 62: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 62/105

Let's add a poster attribute and some clickhandlers

Page 63: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 63/105

Video Poster

Very different behavior in different browsers

#HTML5Video

Stretch poster image to <video> element size, or fit proportionally

May replace poster image with a paused frame from the video

May overlay a play icon that is different for each platform

·

·

·

63/105

Page 64: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 64/105

Video Poster Pro Tips

Protips for a consistent look:

#HTML5Video

Render your own cued state: <img> for the poster, play icon

Replace with the <video> when it's time to play

Set the background color to black for continuity across platforms

·

·

·

64/105

Page 65: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 65/105

How do videos play back?

1. Inline in the page

2. Always fullscreen, no matter what

#HTML5Video

iPad

Android 4.0 and up

Chrome

·

·

·

iPhone, iPod

Android 2.2 - 3.0

Windows Phone

·

·

·

65/105

Page 66: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 66/105

Fullscreen-only <video>

Video element can be stuck anywhere on the page

On webkit, good interaction with your webapp

#HTML5Video

1x1 pixels, or offscreen

but: has to be in the DOM, can't be visibility:hidden or display:none

just call play() to go fullscreen

iPhone: zoom-in animation from <video>'s position

·

·

·

·

Video events still fire: timeupdate, ended etc.

Free to change web page in the background

webkitbeginfullscreen, webkitendfullscreen events

·

·

·

66/105

Page 67: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 67/105

Fullscreen-only <video> caveats

Native controls only

No overlays or custom UI

Can't do captions etc.

#HTML5Video 67/105

Page 68: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 68/105

Controls

#HTML5Video

<video controls>

68/105

Page 69: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 69/105

Controls

Page 70: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 70/105

Native Controls Support

#HTML5Video

Chrome Safari Firefox Opera IE Android

Play/pauseButton

VolumeControls Only in Fullscreen

Mute toggleonly

Don't work inAndroid 4

Seek bar

Fullscreen Button Button and gesture Button

Playback Type Both Fullscreen only onphones

Inline only Determined byhardware

Fullscreenonly

Both

70/105

Page 71: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 71/105

Custom Controls

#HTML5Video

Preserve your brand

Unified experience across platforms and browsers

·

·

71/105

Page 72: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 72/105

Custom Controls

Page 73: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 73/105

Custom Controls

#HTML5Video

Preserve your brand

Unified experience across platforms and browsers

·

·

Allows us to expand the set of controls and add our own·

Annotations

Playlist

Captions

More

-

-

-

-

73/105

Page 74: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 74/105

Custom Controls Pro Tips

#HTML5Video

User expect to be able to drag the progress bar

Volume can't be set everywhere and users are accustomed to using devicecontrols

Fingers are fat

Don't trigger content with hover

Fullscreen

·

Need to remender to prevent scroll on touchstart-

·

So don't build controls for it-

·

Average finger is 11mm so make targets at least 40px with 10px padding

Use SVG's so icons can be scaled and shared with desktop application

-

-

·

·

The browsing context is always fullscreen so fake it-

74/105

Page 75: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 75/105

#HTML5Video

Fullscreen

75/105

Page 76: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 76/105

#HTML5Video

requestFullscreen

76/105

Page 77: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 77/105

#HTML5Video

What about Mobile?

77/105

Page 78: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 78/105

#HTML5Video

Isn't it already fullscreen?

78/105

Page 79: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 79/105

#HTML5Video

Yes (sort of)

79/105

Page 80: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 80/105

Mobile Fullscreen

#HTML5Video

Open New Tab

Remember size context changes so use viewport to scale icons and controls

webkitEnterFullscreen

·

·

@viewport { width: device-width; }-

·

Webkit only

Just the video element

Native controls only

metadata must be loaded

Only in click event

-

-

-

-

-

80/105

Page 81: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 81/105

Autoplay

#HTML5Video

<video autoplay>

81/105

Page 82: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 82/105

Autoplay

#HTML5Video 82/105

Page 83: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 83/105

Autoplay

#HTML5Video

Doesn't work! Restriction: need user action.

Why?

Where?

·

·

On a cell network - users charged for data

Slow downloads, let the user decide

-

-

·

Safari on iOS (iPad included, even on WIFI)

Android Browser (4.0+)

Chrome on Android

-

-

-

83/105

Page 84: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 84/105

Autoplay

#HTML5Video

What about everyone else?

84/105

Page 85: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 85/105

Autoplay Support

#HTML5Video

Chrome Safari Firefox Opera IE Android

Attribute

Scripted Buggy, going away

85/105

Page 86: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 86/105

Autoplay

#HTML5Video 86/105

Page 87: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 87/105

Autoplay

#HTML5Video

<video onclick="this.play()">

87/105

Page 88: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 88/105

Autoplay

#HTML5Video 88/105

Page 89: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 89/105

Autoplay

#HTML5Video 89/105

Page 90: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 90/105

Autoplay

#HTML5Video

<script>

function someClickEvent(evt) {

// In a user initiated thread.

myVideoElement.load(); // Magic incantation to enable play() later on!

getVideoData(); // Triggers an ajax call.

}

function onGetVideoDataReturned(data) {

// Not in a user initiated thread.

setVideoElementSrc(data);

myVideoElement.load();

myVideoElement.play();

}

</script>

JAVASCRIPT

90/105

Page 91: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 91/105

Autoplay

#HTML5Video

<script>

function someClickEvent(evt) {

// In a user initiated thread.

myVideoElement.load(); // Magic incantation to enable play() later on!

getVideoData(); // Triggers an ajax call.

}

function onGetVideoDataReturned(data) {

// Not in a user initiated thread.

setVideoElementSrc(data);

myVideoElement.load();

// For Android

window.setTimeout(function() {

myVideoElement.play();

}, 0);

}

</script>

JAVASCRIPT

91/105

Page 92: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 92/105

Embeds in an HTML5 world

#HTML5Video 92/105

Page 93: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 93/105

Embeds

#HTML5Video

<script>

<object>

<iframe>

·

We need our content to be sandboxed

More than just a video tag

-

-

·

Can load content with the data attribute

But no way to interact with it via JavaScript

-

-

·

Allows our content to be sandboxed

JavaScript API communication

-

-

93/105

Page 94: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 94/105

Embeds

#HTML5Video

<iframe type="text/html"

width="640"

height="385"

frameborder="0"

src="http://www.youtube.com/embed/VIDEO_ID"

allowfullscreen>

</iframe>

HTML

Plan for the future (if you can)·

94/105

Page 95: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 95/105

Iframe Pro Tips

#HTML5Video

html {

/** Hack to fix iPhone resizing. */

overflow: hidden;

}

CSS

body {

/** Dymanic Resizing **/

background-color: #000;

height: 100%;

width: 100%;

/** Remove highlight when use clicks **/

-webkit-tap-highlight-color: rgba(0, 0, 0, 0);

}

CSS

95/105

Page 96: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 96/105

Offline and Storage

http://www.flickr.com/photos/dannykboyd/5048495262/

Page 97: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 97/105

Appcache

#HTML5Video

Offline mode for a video streaming site - useless?

More that just offline access: saves on latency every visit

Pay for code size twice: download + parse time

Saves the download time

·

·

·

·

97/105

Page 98: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 98/105

Appcache

#HTML5Video

<html manifest="manifest_url">

<script src="script.js" />

<link rel="stylesheet" href="style.css" />

</html>

HTML

CACHE MANIFEST

CACHE:

script.js

style.css

NETWORK:

file_to_always_load.jpg

HTML

98/105

Page 99: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 99/105

Appcache - How to force an update?

#HTML5Video

CACHE MANIFEST

CACHE:

foo.js

# Build date: 20120628

HTML

// Random AJAX response

{ "data": ...,

"buildDate": 20120628 }

JAVASCRIPT

var scriptBuildDate = 20120621; // Auto-generated during build or push

if (someResponse.buildDate > scriptBuildDate) {

window.applicationCache.update();

}

JAVASCRIPT

99/105

Page 100: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 100/105

Appcache gotchas

#HTML5Video

GET parameters on cached resources bypass the cache

Strict implementations (eg. iOS5) refuse to download files not in the manifest

since YouTube streams from many domains, we just put

·

·

·

NETWORK: *

Can get wrong in a scary way

Users stuck on old code

Create multiple copies of the entire site in the cache

·

·

·

Easy to break master URL

some redirects to an appcached site: 303 or history.replaceState

history.pushState before background download completes

Some implementations are buggy

·

·

·

·

100/105

Page 101: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 101/105

So is the coolness ready?

Page 102: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 102/105

YesAnd not only do your users want it, they need it

Page 103: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 103/105

<Thank You!>

Page 104: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 104/105

can haz question?

http://www.flickr.com/photos/cloudzilla/378829651/

Page 105: Html5 at YouTube: Stories from the Front Line

4/16/13 HTML5 at YouTube: Stories from the Front Line

gregthebusker.com/html5/html5_at_youtube_u_of_i.html#1 105/105