# aframe-play-sound-on-event

> This is a component for AFRAME which allows events to trigger sounds.

Latest version **1.0.3** (published 2020-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install aframe-play-sound-on-event
pnpm add aframe-play-sound-on-event
yarn add aframe-play-sound-on-event
bun add aframe-play-sound-on-event
```

## 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.3 |
| Published | 2020-01-03 |
| First published | 2019-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Griffin O'Neill |
| Maintainers | eolu |
| Keywords | aframe, aframe-component, aframe-vr, vr, mozvr, webvr |

## Links

- npm: https://www.npmjs.com/package/aframe-play-sound-on-event
- Repository: https://github.com/Eolu/aframe-play-sound-on-event
- Homepage: https://github.com/Eolu/aframe-play-sound-on-event#readme
- Issues: https://github.com/Eolu/aframe-play-sound-on-event/issues
- npm.io page: https://npm.io/package/aframe-play-sound-on-event

## Recent versions

- 1.0.3 (latest) — 2020-01-03
- 1.0.2 — 2019-12-27
- 1.0.1 — 2019-12-27
- 1.0.0 — 2019-12-27

## README

# aframe-play-sound-on-event

This is a component for AFRAME which allows events to trigger sounds. 

## API

| Property | Description | Default Value |
| -------- | ----------- | ------------- |
| event    | The event which triggers sound. | `click` |
| type     | Specifies semantics. See chart below. | `one-shot` |

| Type | Semantics |
| -------- | ----------- |
| `play-only` | When the event is triggered, `playSound()` will be called on the sound component.  |
| `one-shot` | When the event is triggered, `stopSound()` then `playSound()` will be called on the sound component. |
| `toggle-pause` | When the event is triggered, `playSound()` will be called if the sound is stopped or paused, `pauseSound()` will be called if the sound is playing. |
| `toggle-stop` | When the event is triggered, `playSound()` will be called if the sound is stopped or paused, `stopSound()` will be called if the sound is playing. |

Calling `pause()` on this component will disable remove listeners, effectively disabling the functionality of this component. It will not directly pause audio.   
Calling `play()` will recreate listeners if `pause()` has been called previously. Otherwise this will do nothing.

### Installation

#### Browser Installation

Install and use by directly including the [browser files](dist):

```html
<head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/1.0.0/aframe.min.js"></script>
  <script src="https://unpkg.com/aframe-play-sound-on-event@1.0.2/dist/aframe-play-sound-on-event.min.js"></script>
</head>

<body>
  <a-scene>
  
    <a-assets>
      <audio id="ambient_music" src="audio/Coin_Machine.mp3"></audio>
    </a-assets>
    
    <a-entity
      sound="src: #ambient_music"
      play-sound-on-event="mode: toggle-stop; event: click"
      geometry="primitive: box">
    </a-entity>
    
  </a-scene>
</body>
```

#### NPM Installation

Install via NPM:

```bash
npm install aframe-play-sound-on-event
```

Then register and use.

```js
require('aframe');
require('aframe-play-sound-on-event');
```

---
_Source: https://npm.io/package/aframe-play-sound-on-event · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
