Socket
Book a DemoInstallSign in
Socket

capacitor-sound-effect

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capacitor-sound-effect

Native sound effects

3.0.0
latest
Source
npmnpm
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
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

capacitor

FAQs

Package last updated on 06 Dec 2022

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.