Programming6 min read

Capacitor native-audio not playing on Android and loop() hangs

No sound on Android with @capacitor-community/native-audio? Prefix assetPath with public/ and start loops with play(), since loop() in 8.0.0 never resolves.

A sound waveform that fades into a flat line next to an orange circular loop arrow with three waiting dots inside

You start the game on an Android phone, the dice roll across the board, and there is no sound at all. Open the same build in a desktop browser and every click, roll and step is there. Later, with the short effects finally working, the background music still refuses to start, and a console.log placed right after await NativeAudio.loop() never prints.

Two questions come out of that. Why would the same sound files play in the browser and stay silent on the phone? And how can a promise from a plugin simply never come back, with no error and nothing to catch?

That was our morning in ladderGo, our board game, after we added @capacitor-community/native-audio to its Ionic and Angular app. Each problem had a small and specific cause. On Android, assetPath is resolved inside the APK's assets folder, and Capacitor puts your web build there under public/, so assets/sounds/click.mp3 has to be passed as public/assets/sounds/click.mp3. And in version 8.0.0 of the plugin, loop() only switches looping on. It does not start playback, and its promise never settles. Await play() first, then call loop() without awaiting it.

The rest of this post shows where each bug lives in the plugin's Android code, so you can check whether the version you have installed still behaves this way.

How the audio code is set up

ladderGo has one abstract AudioService with two implementations, picked once at bootstrap with Capacitor.isNativePlatform(). A WebAudioService on top of Howler serves the browser, and a NativeAudioService on top of @capacitor-community/native-audio serves Android. The app's package.json asks for ^8.0.0 of the plugin, and 8.0.0 is what is installed, next to @capacitor/core and @capacitor/android ^8.5.0. The native service preloads nine short effects at start, such as click, roll and movement, and loads each game's music and ambience as a "bank" only while that game is open.

Sound is optional in a board game, so every native call is wrapped in try/catch or .catch(() => undefined), because a broken sound must never break a match. That decision is fine. It is also exactly why the first bug was invisible.

Why native-audio plays no sound on Android

This was the preload, with the same paths the web build uses.

ts
await NativeAudio.preload({  assetId: key,  assetPath: SOUNDS[key], // 'assets/sounds/click.mp3'  audioChannelNum: CHANNELS[key] ?? 1,  volume: SOUND_VOLUME,  isUrl: false,});

On Android, preloadAsset in the plugin's NativeAudio.java takes a path that is not a URL and does not start with content, and opens it with AssetManager.openFd). AssetManager paths are relative to the assets/ folder inside the APK. But a Capacitor app does not put your web files at the root of that folder. Running npx cap sync copies the webDir from capacitor.config.ts, which for us is dist/app/browser, into android/app/src/main/assets/public. The file was at public/assets/sounds/click.mp3, the plugin looked for assets/sounds/click.mp3, openFd threw, and the plugin rejected the call with the exception message.

Our catch swallowed that rejection. Because the nine preloads ran in one Promise.all, a single rejection failed the whole preload, the service marked itself as not loaded, and Android had no sound at all. No crash, no red line in the app, just silence.

The assetPath the plugin receives and where the file really is inside the APK
AssetManager resolves assetPath inside the APK's assets folder, and Capacitor puts the web build under public/

The plugin's README says to put Android audio in the native project's assets folder. That works if you keep a second copy of every file there. If your sounds already ship with the web build, as ours do, you do not need the copy. Point at the one Capacitor already put in the APK. The fix is one function that every native preload goes through.

ts
/** * native-audio opens files with Android's AssetManager, relative to the APK's assets folder. * Capacitor copies the web build into `assets/public`, so `assets/sounds/x.mp3` must become * `public/assets/sounds/x.mp3`. */export const nativeAssetPath = (src: string): string =>  src.startsWith('public/') ? src : `public/${src}`;

It has a unit test with both cases. assets/sounds/click.mp3 becomes public/assets/sounds/click.mp3, and a path that already starts with public/ stays as it is. We wrote the test because this is exactly the kind of line someone will "clean up" one day.

Why NativeAudio.loop() never resolves

With the paths fixed, the effects played. The music and the ambience still did not, and something else was odd. The fade-in that should follow the loop never happened. This is how a loop started.

ts
await NativeAudio.setVolume({ assetId: id, volume: 0 }).catch(() => undefined);this.levels.set(id, 0);await NativeAudio.loop({ assetId: id }).catch(() => undefined);this.fadeTo(id, volume * (this.extras.get(id)?.volume ?? 1), fadeMs);

The TypeScript signature is loop(options: { assetId: string }) => Promise<void>, so this looks right. The Android side in 8.0.0 tells a different story. play() and loop() share one method, shown here in a simplified form.

java
private void playOrLoop(String action, final PluginCall call) {    if (audioAssetList.containsKey(audioId)) {        AudioAsset asset = audioAssetList.get(audioId);        if (LOOP.equals(action) && asset != null) {            asset.loop();                 // no call.resolve()        } else if (asset != null) {            asset.play(time, () -> {                call.resolve();                return null;            });        }    }}

One level down, AudioDispatcher.loop() is a single line, mediaPlayer.setLooping(true). That is two bugs in one call. Playback never starts, because only the play path seeks the MediaPlayer) and calls start() when the seek completes. And the bridge call is never resolved or rejected, so await waits forever. The .catch(() => undefined) does not help, since nothing rejects. The code after the await simply never runs. In a Capacitor plugin, the JavaScript promise settles only when the native side calls call.resolve() or call.reject(), as the Capacitor Android plugin guide explains.

Look at the outer if too. When the assetId is not in the list, say because its preload failed, neither branch runs and the call does not settle either, and that goes for play() as well. That is why NativeAudioService keeps its own set of loaded ids and returns early before it calls play() on anything it has not preloaded.

How to fix it with play() first and loop() without await

ts
protected override async startLoopImpl(id: string, volume: number, fadeMs: number): Promise<void> {  if (!this.loadedExtras.has(id)) return;  await NativeAudio.setVolume({ assetId: id, volume: 0 }).catch(() => undefined);  this.levels.set(id, 0);  // native-audio 8.0.0: loop() only sets MediaPlayer looping, never starts playback, and never  // resolves its call. Start with play() (which resolves), then turn looping on without waiting.  await NativeAudio.play({ assetId: id }).catch(() => undefined);  void NativeAudio.loop({ assetId: id }).catch(() => undefined);  this.fadeTo(id, volume * (this.extras.get(id)?.volume ?? 1), fadeMs);}

play() starts the player at volume 0 and resolves. loop() then flips setLooping(true) on a player that is already running, and the void makes it explicit that we do not wait for an answer that never comes. The fade is our own, because the plugin has no per-asset fade. fadeTo steps the volume with setVolume in 10 steps over fadeMs, which is 800 ms by default, so one step every 80 ms.

Call flow of starting a loop with native-audio 8.0.0, before and after the fix
Before the fix, await loop() never settles and MediaPlayer never starts. After it, play() starts and resolves, and loop() only turns looping on.

A Promise.race with a timeout around await loop() would also have unblocked the code, but the player would still be stopped. The order of the calls is the real fix. Both fixes went into the repository on 2026-10-10, 25 minutes apart, two days after the first looping sounds were added.

A loop that stops on its own after a long idle

A month later we saw one more case. After the app sat on the main screen for a long time, the music sometimes just ended, now and then with a click. Android's MediaPlayer can stop a looping track without telling anyone, and the browser can suspend its audio context. The service now keeps a map of the loops that should be sounding and checks them every 5 seconds with LOOP_WATCHDOG_MS = 5_000. On Android the check is NativeAudio.isPlaying(), which does resolve. If a loop that should play is not playing, it is stopped and started again with a 600 ms fade-in. When the app goes to the background, the service unloads every native player, and it preloads them again on resume.

If you are fixing this right now, list your APK and pass the path exactly as it appears after assets/. Replace every await NativeAudio.loop() with an awaited play() followed by a loop() you do not await, and never call the plugin with an id you have not preloaded. Check the plugin's releases and its npm page before you copy the workaround, since what we describe is 8.0.0 as installed in our repository. You can hear the result in ladderGo.

Topics:#capacitor#android#audio#ionic

Written by

Amin Norollah

Full-stack developer and team lead with 14+ years in software: .NET, Java and Node.js backends, Angular front ends, and systems for payments, trading and industry. Before that, a researcher at IUST with Université Grenoble Alpes, with 13 papers (IEEE, Elsevier) on hardware security, real-time scheduling and network-on-chip.

norollah.com
How to cite this article

Amin Norollah, "Capacitor native-audio not playing on Android and loop() hangs", toyfox blog, December 3, 2026, https://toyfox.app/en/blog/capacitor-native-audio-android-no-sound/

Live

Seven board and party games in your pocket

Snakes & Ladders, Ludo, Dots & Boxes, Connect Four, Mill, Mirage and Lemon Rush in one free app on Google Play. Play offline vs bots or online with friends.

All posts
ladderGo on Google Play

Release1 min readPinned

ladderGo is out on Google Play

Seven board and party games in one free app: play offline against bots, pass one phone around or join an online table with real people.

ladderGo 1.24.0

Fair play in ladderGo

Devlog1 min read

Fair play in ladderGo

Nothing you can buy helps you win, ads are always your choice, and you never need to sign up.

ladderGo