Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
feat: add castable-video (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed May 20, 2022
1 parent c90bbb0 commit 5f32587
Show file tree
Hide file tree
Showing 7 changed files with 2,376 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/node_modules/
54 changes: 54 additions & 0 deletions README.md
@@ -0,0 +1,54 @@
# `is="castable-video"`

Cast your video element to the big screen with ease!

The lightweight `CastableVideo` class extends the native `HTMLVideoElement` API and adds casting functionality to any video element. The API was designed to have the feel of a native browser API similar to the other screen presentation API's.

It was primarily built for use in [Media Chrome](https://github.com/muxinc/media-chrome) but it works great with any custom video controls as you can see in the example.


```html
<script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
<script type="module" src="./castable-video.js"></script>

<video
id="castable"
is="castable-video"
src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4"
></video>

<button onclick="window.castable.play()">Play</button>
<button onclick="window.castable.pause()">Pause</button>
<button onclick="window.castable.requestCast()">Request Cast</button>
<button onclick="window.CastableVideo.exitCast()">Exit Cast</button>
<script>
window.castable.addEventListener('castchange', function (event) {
console.log(event.type, event.detail);
});
</script>
```

## API

### Methods

- `video.requestCast(options)`
- `CastableVideo.exitCast()`

### Properties

- `CastableVideo.castElement`
- `CastableVideo.castAvailable`

### Events

- `entercast`
- `leavecast`
- `castchange`

e.g. `video.addEventListener('entercast', () => {})`

### Attributes

- `stream-type`: add `<video "stream-type="live">` for live streams.
- `cast-src`: if Chromecast requires a different source than the one loaded.

1 comment on commit 5f32587

@vercel
Copy link

@vercel vercel bot commented on 5f32587 May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

castable-video – ./

castable-video.vercel.app
castable-video-git-main-mux.vercel.app
castable-video-mux.vercel.app

Please sign in to comment.