Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jermspeaks/autoplay-detection
Browser-based autoplay with sound on detector
https://github.com/jermspeaks/autoplay-detection
audio autoplay browsers video
Last synced: 22 days ago
JSON representation
Browser-based autoplay with sound on detector
- Host: GitHub
- URL: https://github.com/jermspeaks/autoplay-detection
- Owner: jermspeaks
- Created: 2017-10-06T18:39:20.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-06T21:42:22.000Z (about 7 years ago)
- Last Synced: 2024-10-02T09:10:28.754Z (3 months ago)
- Topics: audio, autoplay, browsers, video
- Language: JavaScript
- Homepage:
- Size: 202 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Autoplay Detection
**This Library is not production ready yet. Use with discretion.**
A small library to detect if autoplay with sound is working on the page.
## Installation
The package is bundled with [UMD](https://github.com/umdjs/umd), so there's support for AMD, CommonJS, and RequireJS.
### Example
```html
```
## Usage
The library exposes a global variable called "autoplayDetector" with a single function that returns a promise, `canAutoplay`. The promise returns a `Boolean` whether this browser can autoplay with sound on. The promise is rejected if the browser does not support video, or support promises, or supports proper video attributes outlined in [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement).
```js
autoplayDetector.canAutoplay().then(canUse => {
if (canUse) {
console.log('Yes, this browser can autoplay');
} else {
console.log('Nope, this browser cannot autoplay');
}
}).catch(error) {
console.log("If you're browser is this old, it needs to support video attributes.", error);
};
```