The iPhone has certain restrictions in playing audio in the web browser. This example shows how to successfully play audio on mobile.
The sound effect will play when the camera moves within a certain distance of the target object. The user will need to tap the iPhone screen (once) to allow sounds to play.
- Add script.js to your project.
- Add the script link to
howler
in your project. - Add an
<assets>
section that lists your audio files. - To add audio to element when the camera moves close to it, include an
audio
attribute as shown below.<a-box src="url(images/box.png); audio="src: #mysound; loop: true;"></a-box>
- Tap the iPhone screen after opening the app. This user action is required in order to allow sounds in the iOS web browser.
Sound module in A-Frame.
Free sound effects.