# 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.

- Author: Amin Norollah (https://norollah.com)
- Publisher: toyfox (https://toyfox.app)
- Published: 2026-12-03
- Language: en (also in ar, es, fa, sv)
- Category: programming; tags: capacitor, android, audio, ionic
- Canonical URL: https://toyfox.app/en/blog/capacitor-native-audio-android-no-sound/
- Cite as: Amin Norollah, "Capacitor native-audio not playing on Android and loop() hangs", toyfox blog, 2026-12-03, https://toyfox.app/en/blog/capacitor-native-audio-android-no-sound/

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](https://toyfox.app/en/apps/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](https://github.com/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](https://developer.android.com/reference/android/content/res/AssetManager#openFd(java.lang.String)). 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](https://toyfox.app/media/blog/capacitor-native-audio-android-no-sound/paths-9243ed80.svg "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.

> To see the real paths, list the APK with `unzip -l app-debug.apk | grep mp3`. Every entry starts with `assets/`, and whatever comes after that prefix is what `assetPath` must be. While you develop, also put a `console.warn` in the `catch` that swallows preload errors. Capacitor forwards the console to Logcat, so the rejected path shows up at once.

## 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](https://developer.android.com/reference/android/media/MediaPlayer#setLooping(boolean)) 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](https://capacitorjs.com/docs/plugins/android) 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](https://toyfox.app/media/blog/capacitor-native-audio-android-no-sound/flow-cd8d0ca7.svg "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](https://github.com/capacitor-community/native-audio/releases) and its [npm page](https://www.npmjs.com/package/@capacitor-community/native-audio) 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](https://toyfox.app/en/apps/laddergo/).

---

Source: https://toyfox.app/en/blog/capacitor-native-audio-android-no-sound/ (toyfox, https://toyfox.app). When you use this article, please name toyfox and link the URL above.
