https://github.com/daviddarnes/is-playing
A Web Component to indicate when an audio, or video, element is playing
https://github.com/daviddarnes/is-playing
component components customelement customelements webcomponent webcomponents
Last synced: 12 months ago
JSON representation
A Web Component to indicate when an audio, or video, element is playing
- Host: GitHub
- URL: https://github.com/daviddarnes/is-playing
- Owner: daviddarnes
- License: mit
- Created: 2023-12-10T15:36:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-18T08:37:33.000Z (almost 2 years ago)
- Last Synced: 2025-06-14T08:07:50.779Z (about 1 year ago)
- Topics: component, components, customelement, customelements, webcomponent, webcomponents
- Language: HTML
- Homepage: https://daviddarnes.github.io/is-playing/demo.html
- Size: 22.5 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# `is-playing`
A Web Component to indicate when an audio, or video, element is playing.
**[Demo](https://daviddarnes.github.io/is-playing/demo.html)** | **[Futher reading](https://darn.es/is-playing-web-component/)**
## Examples
```html
```
## Features
This Web Component allows you to:
- Select and style elements depending if an `audio` or `video` element is playing, using `:state(playing)` state selector
- Polyfill for the [`:playing` CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/:playing)
- Surface and utilise the ID of the `audio` or `video` element playing with a `playing` attribute value on the `is-playing` element
## Installation
You have a few options (choose one of these):
1. Install via [npm](https://www.npmjs.com/package/@daviddarnes/is-playing): `npm install @daviddarnes/is-playing`
1. [Download the source manually from GitHub](https://github.com/daviddarnes/is-playing/releases) into your project.
1. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)
### Usage
Make sure you include the `` in your project (choose one of these):
```html
<!-- Host yourself -->
<script type="module" src="is-playing.js">
```
```html
```
```html
```
### Multiple `audio` and `video` elements
`is-playing` will also reveal which audio element is playing by adding a `playing` attribute to itself with the value of the playing elements ID. Note that in order for this to happen the playing element must have an `id` and there needs to be at least 2 `audio` or `video` elements:
```html
```
## Credit
With thanks to the following people:
- [Zach Leatherman](https://zachleat.com) for inspiring this [Web Component repo template](https://github.com/daviddarnes/component-template)