npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-ui-sounds

v1.2.2

Published

Cordova Plugin for simple audio feedback on mobile devices.

Downloads

76

Readme

cordova-plugin-ui-sounds

This is a Cordova plugin to add simple audio feedback to your mobile applications.

In creating this plugin, we had the following goals:

  • Mix with other audio playing on the device without interruption or ducking.
  • Low-latency playback with little-to-no impact on the main thread.
  • No visible audio playback UI on the device or any paired wearable devices.

Installation

Use the usual command-line to install this plugin within your Cordova-based project:

cordova plugin add cordova-plugin-ui-sounds

Usage

// During app initialization, after deviceReady:
var uiSounds = cordova.require('cordova-plugin-ui-sounds.Plugin');
uiSounds
  .preloadSound('assets/myTapSound.mp3')
  .catch(error => console.error(error));

// During button press event:
var myVolume = 1.0;
uiSounds.playSound('assets/myTapSound.mp3', myVolume);

// If you will never use the sound again:
uiSounds.unloadSound('assets/myTapSound.mp3');

API

preloadSound(assetPath)

Loads a sound asset so that it is already in memory when a subsequent playSound call is made.

In order to achieve low latency between UI events and audio feedback, it is good practice to call preloadSound for each of your app's sound effects after deviceReady.

  • assetPath (string) - Tells the operating system where to find the sound file. This must be a path relative to your project's www folder. It is case-sensitive.
  • Return Value (Promise<string>) - Promise containing an appropriate success or failure message. Resolves when the asset has finished loading.

preloadMultiple(arrayOfAssetPaths)

Loads multiple sound assets at a time.

In order to achieve low latency between UI events and audio feedback, it is good practice to pre-load all of your app's sound effects after deviceReady.

  • arrayOfAssetPaths (string[]) - Tells the operating system where to find each sound file. Each string in this array must be a path relative to your project's www folder. It is case-sensitive.
  • Return Value (Promise<string>) - Promise containing an appropriate success or failure message. Resolves when all assets have finished loading.

playSound(assetPath, [volume])

Plays a sound asset on the device's system audio channel.

If the sound has not been loading yet using preloadSound, it will be loaded before playing.

  • assetPath (string) - Tells the operating system where to find the sound file. This must be a path relative to your project's www folder. It is case-sensitive.
  • volume (double, optional) - Indicates the desired playback volume of this sound relative to other system sounds. This parameter is ignored on iOS (see iOS Limitations). It no value is given, this parameter will default to 1.0.
  • Return Value (Promise<string>) - Promise containing an appropriate success or failure message. Resolves when the asset has started playback.

unloadSound(assetPath)

Frees the resources associated with the given sound asset.

If you no longer need a sound asset, it is good practice to free the resource using this method.

  • assetPath (string) - Tells the operating system where to find the sound file. This must be a path relative to your project's www folder. It is case-sensitive.
  • Return Value (Promise<string>) - Promise containing an appropriate success or failure message. Resolves when the asset has been unloaded.

Limitations

As this plugin is intended to play quick UI feedback sound effects:

  • Sounds play immediately
  • Looping and stereo positioning are unavailable
  • Simultaneous playback is unavailable: You can play only one sound at a time
  • The sound is played locally on the device speakers; it does not use audio routing.
  • Playback volume is linked to the device's system audio channel, meaning no sounds are played while the device is in silent/vibrate mode.

iOS Limitations

From the official Apple documentation, sound files that you play using this plugin must be:

  • No longer than 30 seconds in duration
  • In linear PCM or IMA4 (IMA/ADPCM) format
  • Packaged in a .caf, .aif, or .wav file (note: .mp3 seems to work just fine as well)

In addition:

  • Sounds play at the current system audio volume, with no programmatic volume control available

Android Limitations

A number of audio file formats are supported (see the full list): .mp3, .mp4, .flac, .wav, .ogg

Unlike iOS, programmatic volume control is available on Android (relative to the system sound channel).

Alternatives

HTML Audio

cordova-plugin-nativeaudio

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

MIT