# detect-media-element-source

> detects whether the browser supports WebAudio music streaming

Latest version **1.1.2** (published 2016-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install detect-media-element-source
pnpm add detect-media-element-source
yarn add detect-media-element-source
bun add detect-media-element-source
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2016-06-23 |
| First published | 2015-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | test, detect, detects, webaudio, web, audio, source, music, stream, streaming, streams |

## Links

- npm: https://www.npmjs.com/package/detect-media-element-source
- Repository: https://github.com/Jam3/detect-media-element-source
- Issues: https://github.com/Jam3/detect-media-element-source/issues
- npm.io page: https://npm.io/package/detect-media-element-source

## Dependencies (2)

- [once](https://npm.io/package/once.md) ^1.3.3
- [audiobuffer-to-wav](https://npm.io/package/audiobuffer-to-wav.md) ^1.0.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2016-06-23
- 1.1.1 — 2016-06-17
- 1.1.0 — 2016-06-17
- 1.0.3 — 2015-11-26
- 1.0.2 — 2015-11-26
- 1.0.1 — 2015-11-26
- 1.0.0 — 2015-11-26

## README

# detect-media-element-source

[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)

Detects whether the browser correctly supports WebAudio's `createMediaElementSource()`, by playing a short looping noise segment and seeing whether signal is non-zero.

For example: Desktop Chrome/FF support media element sources, but mobile iOS 9.2 Safari does not. In unsupported browsers, you need to buffer and decode the entire audio file in order to use it with the WebAudio API.

##### Note :warning:

Because of the way the WebAudio and browser APIs are constantly in flux, this may not be a robust and long-term solution to detecting this feature. There is no reliable way to detect this feature across all browsers, except for actually watching the result of an AnalyserNode over your own `<audio>` source, and then falling back to a buffer source in such a case. However, that requires additional UX hurdles on mobile (for touch-to-play audio).

## Install

```sh
npm install detect-media-element-source --save
```

## Example

```js
var detectMedia = require('detect-media-element-source')

detectMedia(function (supported) {
  if (supported) {
    // ... audioContext.createMediaElementSource()
  } else {
    // ... audioContext.createBufferSource()
  }
})
```

## Usage

[![NPM](https://nodei.co/npm/detect-media-element-source.png)](https://www.npmjs.com/package/detect-media-element-source)

#### `detectMediaElementSource(cb, [audioContext], [timeoutDelay], [ignoreCache])`

Detects whether `createMediaElementSource` works as expected with the WebAudio API, calling `cb` with `true` if supported, `false` otherwise.

`audioContext` is optional (a new temporary context will be used) but encouraged.

`timeoutDelay` defaults to 250ms (550ms if userAgent shows Safari), but can be configured to allow the loop to play for a longer/shorter time before deciding the result.

## License

MIT, see [LICENSE.md](http://github.com/Jam3/detect-media-element-source/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/detect-media-element-source · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
