1.0.3 • Published 4 years ago

aframe-play-sound-on-event v1.0.3

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

aframe-play-sound-on-event

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

API

PropertyDescriptionDefault Value
eventThe event which triggers sound.click
typeSpecifies semantics. See chart below.one-shot
TypeSemantics
play-onlyWhen the event is triggered, playSound() will be called on the sound component.
one-shotWhen the event is triggered, stopSound() then playSound() will be called on the sound component.
toggle-pauseWhen 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-stopWhen 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:

<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:

npm install aframe-play-sound-on-event

Then register and use.

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