Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/otiai10/fresh-youtube

View component and controller of YouTube Player API, for fresh framework.
https://github.com/otiai10/fresh-youtube

deno fresh preact react typescript youtube youtube-player

Last synced: 3 months ago
JSON representation

View component and controller of YouTube Player API, for fresh framework.

Awesome Lists containing this project

README

        

# fresh-youtube

[![Deno CI](https://github.com/otiai10/fresh-youtube/actions/workflows/deno-ci.yml/badge.svg)](https://github.com/otiai10/fresh-youtube/actions/workflows/deno-ci.yml)
[![Deploy Example](https://github.com/otiai10/fresh-youtube/actions/workflows/deploy-example.yml/badge.svg)](https://fresh-youtube.deno.dev/)

View component and controller of
[YouTube Player API](https://developers.google.com/youtube/iframe_api_reference),
for [fresh framework](https://github.com/denoland/fresh).

# Try it now!

```
git clone [email protected]:otiai10/fresh-youtube.git
cd ./fresh-youtube
cd ./example
deno task start
```

example

# Example

See
[./example/islands/ExampleIsland.ts](https://github.com/otiai10/fresh-youtube/blob/main/example/islands/ExampleIsland.tsx).

```tsx
/** @jsx h */
import { h } from "preact";
import { useMemo, useState } from "preact/hooks";

import {
PlayerState,
YouTubePlayerDelegate,
YouTubePlayerView,
} from "https://deno.land/x/[email protected]/mod.ts";

export default function ExampleIsland() {
// This is what we already know: useState to see dynamic value.
const [playerState, setPlayerState] = useState(
PlayerState.UNSTARTED,
);

// Then, let's create a delegated object to access what happens in YT player.
const delegate = useMemo(() =>
new YouTubePlayerDelegate({
stateUpdater: setPlayerState,
initialVideoID: "MGt25mv4-2Q",
}), []); // Please use `useMemo` to avoid repeated initialization.

// Finally, you can render the View!
return (


{/* You don't have to worry about YT or any other mess! */}

{/* Yes, you can access what's happening now by the `state`! */}


{playerState}: {PlayerState[playerState]}

{/* Wanna control? Sure, everything is delegated to your object! */}
delegate.play()}
disabled={playerState == PlayerState.PLAYING}
>
PLAY

delegate.pause()}
disabled={playerState == PlayerState.PAUSED}
>
PAUSE


);
}
```

# Acknowledgment

- https://github.com/itok01/fresh-youtube-player
- https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/youtube
- https://developers.google.com/youtube/iframe_api_reference
- https://github.com/denoland/fresh
- https://github.com/preactjs/preact