ガイド
ネイティブオーディオのチュートリアル
Using @capgo/native-audio
ネイティブオーディオエンジン用のネイティブプラグイン。
インストール
bun add @capgo/native-audio
bunx cap sync
このプラグインが公開するもの
configure- オーディオプレーヤーの設定preload- オーディオファイルの読み込みplayOnce- オーディオファイルの再生(自動クリーンアップ)isPreloaded- __CAPGO_KEEP_0__ が事前に読み込まれているかを確認します。
Example Usage
configure
オーディオ プレーヤーを設定します。
import { NativeAudio } from '@capgo/native-audio';
await NativeAudio.configure({} as ConfigureOptions);
preload
オーディオ ファイルを読み込みます。
import { NativeAudio } from '@capgo/native-audio';
await NativeAudio.preload({} as PreloadOptions);
playOnce
オーディオ ファイルを 1 回再生し、自動でクリーンアップします。
import { NativeAudio } from '@capgo/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
オーディオ ファイルが事前に読み込まれているかを確認します。
import { NativeAudio } from '@capgo/native-audio';
await NativeAudio.isPreloaded({} as PreloadOptions);
Full Reference
- GitHub: https://github.com/Cap-go/capacitor-native-audio/
- Docs: /docs/plugins/native-audio/