NativeScript Sound
Play a sound in your NativeScript app.
Installation
Run the following command from the root of your project:
tns plugin add nativescript-sound
Usage
To use this plugin you must first require() it:
var sound = ;
create and play
It's important to preload the audio file into the sound module before playing it; there is a delay during creation due to the audio being processed:
var tada = sound; // preload the audio file // play the sound (i.e. tap event handler)tada;
A good way to do this is to create a sound collection:
sounds = "Tada": sound "Boo": sound // ...;
If you wish to play a sound due to a button being tapped, leverage the following code (where name
refers to the name of the audio file to be played):
this { if appandroid soundsname; else var soundFile = sound; soundFile; }
stop
tada;
reset
tada;