Skip to content

Commit

Permalink
rejiggle readme. add section on getPlayer()
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Mar 3, 2024
1 parent 12cbfa1 commit 1a76a7a
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ To use the custom element you will need to:
Privacy note: lite-youtube uses youtube-nocookie.com instead of youtube.com in order
to be more privacy friendly for end users.

### Custom Player Parameters

YouTube supports a variety of [player parameters](https://developers.google.com/youtube/player_parameters#Parameters) to control the iframe's behavior and appearance.
These may be applied by using the `params` attribute.

```html
<!-- Example to show a video player without controls, starting at 10s in, ending at 20s,
with modest branding *and* enabling the JS API -->
<lite-youtube videoid="ogfYd705cRs" params="controls=0&start=10&end=30&modestbranding=2&rel=0&enablejsapi=1"></lite-youtube>
```

Note that lite-youtube uses `autoplay=1` by default.

Demo: https://paulirish.github.io/lite-youtube-embed/variants/params.html

## Pro-usage: load w/ JS deferred (aka progressive enhancement)

Use this as your HTML, load the script asynchronously, and let the JS progressively enhance it.
Expand All @@ -66,7 +51,7 @@ Use this as your HTML, load the script asynchronously, and let the JS progressiv
</lite-youtube>
```

Demo: https://paulirish.github.io/lite-youtube-embed/variants/pe.html
[Demo: progressive enhancement](https://paulirish.github.io/lite-youtube-embed/variants/pe.html)

## Custom poster image

Expand All @@ -77,14 +62,40 @@ If you want to provide a custom poster image, just set it as the background-imag

Use [poster-image-availability.html](https://paulirish.github.io/lite-youtube-embed/testpage/poster-image-availability.html) to determine what poster images are available for you.

## Access the YouTube Iframe Player API

Use the `js-api` param: `<lite-youtube videoid="ogfYd705cRs" js-api>`.. Then you can use [IFrame Player API](https://developers.google.com/youtube/iframe_api_reference):

```js
const player = await document.querySelector('lite-youtube').getPlayer();
player.seekTo(15); // jump to 15 seconds
```

[Demo: Iframe Player API usage](https://paulirish.github.io/lite-youtube-embed/variants/js-api.html)

## Add a video title

If you want to display a title prior to loading the full embed, set the `title` attribute:
```html
<lite-youtube videoid="ogfYd705cRs" title="Keynote (Google I/O '18)"></lite-youtube>
```

Demo: https://paulirish.github.io/lite-youtube-embed/variants/title.html
[Demo: visible title](https://paulirish.github.io/lite-youtube-embed/variants/title.html)

### Custom Player Parameters

YouTube supports a variety of [player parameters](https://developers.google.com/youtube/player_parameters#Parameters) to control the iframe's behavior and appearance.
These may be applied by using the `params` attribute.

```html
<!-- Example to show a video player without controls, starting at 10s in, ending at 20s,
with modest branding *and* enabling the JS API -->
<lite-youtube videoid="ogfYd705cRs" params="controls=0&start=10&end=30&modestbranding=2&rel=0&enablejsapi=1"></lite-youtube>
```

Note that lite-youtube uses `autoplay=1` by default.

[Demo: Custom player parameters](https://paulirish.github.io/lite-youtube-embed/variants/params.html)

## Other fast YouTube embeds

Expand Down

0 comments on commit 1a76a7a

Please sign in to comment.