Skip to main content
@capgo/capacitor-native-audio Renamed Renamed from @capgo/native-audio to @capgo/capacitor-native-audio. Media Open source

Native Audio Capacitor plugin

Play short audio files with low latency using native audio engine for games and apps

Install

bun add @capgo/capacitor-native-audio bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-native-audio
  • pnpm add @capgo/capacitor-native-audio
  • yarn add @capgo/capacitor-native-audio

Guide

How to use Native Audio in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

Native Audio plugin preview QR code

Using @capgo/capacitor-native-audio

A native plugin for native audio engine.

Install

npm install @capgo/capacitor-native-audio
npx cap sync

What This Plugin Exposes

  • configure - Configure the audio player.
  • preload - Load an audio file.
  • playOnce - Play an audio file once with automatic cleanup.
  • isPreloaded - Check if an audio file is preloaded.

Example Usage

configure

Configure the audio player.

import { NativeAudio } from '@capgo/capacitor-native-audio';

await NativeAudio.configure({
  focus: false,
  background: false,
  ignoreSilent: false,
  showNotification: false,
  backgroundPlayback: false,
});

preload

Load an audio file.

import { NativeAudio } from '@capgo/capacitor-native-audio';

await NativeAudio.preload({
  assetPath: 'path/to/file',
  assetId: 'asset-id-123',
});

playOnce

Play an audio file once with automatic cleanup.

import { NativeAudio } from '@capgo/capacitor-native-audio';

// Simple one-shot playback
await NativeAudio.playOnce({ assetPath: 'audio/notification.mp3' });

// Play and delete the file after completion
await NativeAudio.playOnce({
  assetPath: 'file:///path/to/temp/audio.mp3',
  isUrl: true,
  deleteAfterPlay: true
});

// Get the assetId to control playback
const { assetId } = await NativeAudio.playOnce({
  assetPath: 'audio/long-track.mp3',
  autoPlay: true
});
// Later, you can stop it manually if needed
await NativeAudio.stop({ assetId });

isPreloaded

Check if an audio file is preloaded.

import { NativeAudio } from '@capgo/capacitor-native-audio';

const result = await NativeAudio.isPreloaded({
  assetPath: 'path/to/file',
  assetId: 'asset-id-123',
});
console.log(result);

Full Reference

Keep going from Using @capgo/capacitor-native-audio

If you are using Using @capgo/capacitor-native-audio to plan native media and interface behavior, connect it with @capgo/capacitor-native-audio for the implementation detail in @capgo/capacitor-native-audio, Getting Started for the implementation detail in Getting Started, Using @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, and Using @capgo/capacitor-video-player for the native capability in Using @capgo/capacitor-video-player.

FAQ

Native Audio plugin FAQ

How do I install the Native Audio plugin in a Capacitor app?

Run "bun add @capgo/capacitor-native-audio" (or "npm install @capgo/capacitor-native-audio"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-native-audio" in your app code.

Does @capgo/capacitor-native-audio work with React, Vue and Angular?

Yes. Native Audio is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-native-audio support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-native-audio free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-native-audio/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Native Audio without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Native Audio changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo