# ios-safe-audio-context

> create a WebAudio context that works in iOS and everywhere else

Latest version **1.0.1** (published 2015-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install ios-safe-audio-context
pnpm add ios-safe-audio-context
yarn add ios-safe-audio-context
bun add ios-safe-audio-context
```

## 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.0.1 |
| Published | 2015-11-25 |
| First published | 2015-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | web, audio, context, hack, ios, sampleRate, bug, 44100, fix, workaround, issue, webaudio, iphone, ipad |

## Links

- npm: https://www.npmjs.com/package/ios-safe-audio-context
- Repository: https://github.com/Jam3/ios-safe-audio-context
- Issues: https://github.com/Jam3/ios-safe-audio-context/issues
- npm.io page: https://npm.io/package/ios-safe-audio-context

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-11-25
- 1.0.0 — 2015-11-25

## README

# ios-safe-audio-context

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

Creates a `AudioContext` that works as expected in desktop and mobile, particularly across iOS devices.

### Motivation

There is a [bug in iOS](http://stackoverflow.com/questions/26336040/how-to-fix-changing-sample-rate-bug) where the AudioContext `sampleRate` is sometimes not what you would expect, and as a result, all WebAudio plays with heavy distortion. This occurs when you play an audio/video element with a different sample rate, or when you first boot up Safari (tested on iOS9.2, iPhone5S, no headphones).

To get around this, we try to detect a broken state, and if so, play a dummy buffer before returning a *new* AudioContext which should have the desired sample rate (default 44100).

## Example

On iOS, this function must be called from user gesture event, such as `touchend`.

```js
const createAudioContext = require('ios-safe-audio-context')

clickToPlay.addEventListener('touchend', () => {
  const audioContext = createAudioContext()
  
  // now you can use this context for playback
})
```

## Usage

[![NPM](https://nodei.co/npm/ios-safe-audio-context.png)](https://www.npmjs.com/package/ios-safe-audio-context)

#### `context = createAudioContext([desiredSampleRate])`

Returns a new AudioContext, only applying the hack if we detect a broken state (iOS). `desiredSampleRate` defaults to 44100.

## License

MIT, see [LICENSE.md](http://github.com/Jam3/ios-safe-audio-context/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/ios-safe-audio-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
