Socket
Socket
Sign inDemoInstall

capacitor-sound-effect

Package Overview
Dependencies
2
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    capacitor-sound-effect

Native sound effects


Version published
Weekly downloads
17
increased by750%
Maintainers
1
Install size
21.6 kB
Created
Weekly downloads
 

Readme

Source

capacitor-sound-effect

This plugin provides the ability to natively play sound effects in Capacitor based projects.

Install

General

npm install capacitor-sound-effect
npx cap sync

Ionic

npm install capacitor-sound-effect
ionic cap sync

API

  • loadSound(...)
  • play(...)

loadSound(...)

loadSound(options: { id: string; path: string; }) => any
ParamType
options{ id: string; path: string; }

Returns: any


play(...)

play(options: { id: string; }) => any
ParamType
options{ id: string; }

Returns: any


Usage Example

This example is based on an Ionic (Vue) project, but is generally applicable to other scenarios

Import the plugin
import { SoundEffect } from 'capacitor-sound-effect';
Load the sounds

In Ionic, the path is relative to your 'public' directory. So for a file located in /public/assets/sounds/, the below is applicable:

loadSounds() {
    SoundEffect.loadSound({id:'message', path:'assets/sounds/message.mp3'});
    SoundEffect.loadSound({id:'status', path:'assets/sounds/status.mp3'});
}

You must pass an object, as illustrated above, to the loadSound() method. The 'id' must be unique as it is used to reference the sound when you come to playing.

Play a sound

When playing a sound, you must reference the 'id' you provided during loadSound().

SoundEffect.play({id:'message'});

Keywords

FAQs

Last updated on 06 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc