Skip to main content
Back to plugins
@capgo/capacitor-native-audio Renamed Renamed from @capgo/native-audio to @capgo/capacitor-native-audio.
Tutorial
@capgo/capacitor-native-audio

Native Audio

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

Guide

Tutorial on Native Audio

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({} as ConfigureOptions);

preload

Load an audio file.

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

await NativeAudio.preload({} as PreloadOptions);

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';

await NativeAudio.isPreloaded({} as PreloadOptions);

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.