cordova-plugin-nativesounds
v0.0.10
Published
Cordova plugin for getting native sounds on android and ios
Downloads
6
Readme
Native Sounds Cordova Plugin
- Now with support for iOS and Android *
Just specify an array of class strings and on an onclick event, it will trigger the default specified sound for the platform. Also you can trigger the sound manually.
Android part based on a blog post from @pieterderycke
Note
Apparently the android alarm and ringtone sounds play infinitely for some reason. Push notification sound seems to stutter a bit. (this was not tested on a real device but an emulator).
Warning: Some of the current ios code might be deprecated in the near future, I will add a fix for that soon.
Installation
cordova plugin add cordova-plugin-nativesounds
Exported Members
nativeClickSound
nativeNavUpSound
nativeNavDownSound
nativeNavLeftSound
nativeNavRightSound
nativePushNotSound
nativeAlarmSound
nativeRingtoneSound
Android only
The following sound effects are android only and will not play any sound on ios:
nativeNavUpSound nativeNavDownSound nativeNavLeftSound nativeNavRightSound
Usage
If using this plugin with typescript simply declare var nativesound
after your imports in your component ts file.
For any of the exported members you can call either watch(classes), to watch for an array list of classes to trigger the sound on. Or you can trigger the sound manually with trigger()
To trigger them on specific html classes:
var classes = ['sound-click', 'button'];
nativesound.nativeClickSound.watch(classes);
nativesound.nativeNavUpSound.watch(classes);
nativesound.nativeNavDownSound.watch(classes);
nativesound.nativeNavLeftSound.watch(classes);
nativesound.nativeNavRightSound.watch(classes);
nativesound.nativePushNotSound.watch(classes);
nativesound.nativeAlarmSound.watch(classes);
nativesound.nativeRingtoneSound.watch(classes);
To trigger them manually:
nativesound.nativeClickSound.trigger();
nativesound.nativeNavUpSound.trigger();
nativesound.nativeNavDownSound.trigger();
nativesound.nativeNavLeftSound.trigger();
nativesound.nativeNavRightSound.trigger();
nativesound.nativePushNotSound.trigger();
nativesound.nativeAlarmSound.trigger();
nativesound.nativeRingtoneSound.trigger();
If you're using angular for example:
<!-- In the component html -->
<button (click)="click()"></button>
// In the component's ts file
click() {
nativesound.nativeClickSound.trigger();
};
Credits
This plugin is a expansion on the plugin located here: (https://github.com/MatiMenich/cordova-plugin-nativeClickSound)
Credits go to Matías Menich for creating the native click sound plugin, which this is a fork of.
License
Copyright (c) 2015 Matías Menich
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.