native-audio-player

February 1, 2026 ยท View on GitHub

Play native audio from a Capacitor app.

โœจ Features

  • ๐Ÿ”ˆ Toggle between Speaker and Earpiece as audio output
  • ๐ŸŽถ Audio keeps playing in the background, when app is minimized
  • ๐Ÿ”“ Native players in notifications and lock screens
  • ๐Ÿ“ฑ Support for Android, iOS, Web (only Speaker)

Maintainers

MaintainerGitHubSocial
Stefan HuberstefanhuberLinkedin

Install

npm install @smartcompanion/native-audio-player
npx cap sync

Configuration

PlatformConfiguration
iOSAudio has to be added as Background Mode within Signing & Capabilities of the app, in order to keep audio playing in the background
AndroidThe plugin has a AndroidManifest.xml, which includes all configurations

Usage

In folder ./example a full usage example is available. This example is also used for automated and manual testing.

Demo AppNative Audio Player
Demo App ScreenNative Audio Player (Android)

Other Audio Player Plugins

API

setEarpiece()

setEarpiece() => Promise<void>

Set the audio output to the earpiece.


setSpeaker()

setSpeaker() => Promise<void>

Set the audio output to the speaker.


start(...)

start(options: StartOptions) => Promise<{ id: string; }>

Initialize the audio player with a list of audio items.

ParamTypeDescription
optionsStartOptions- The options for starting the audio player.

Returns: Promise<{ id: string; }>


stop()

stop() => Promise<void>

Stop the currently playing audio item and clear the playlist.


play()

play() => Promise<void>

Play the currently selected audio item.


pause()

pause() => Promise<void>

Pause the currently playing audio item.


select(...)

select(options: { id: string; }) => Promise<{ id: string; }>

Select an audio item from the playlist by its id.

ParamType
options{ id: string; }

Returns: Promise<{ id: string; }>


next()

next() => Promise<{ id: string; }>

Skip to the next audio item in the playlist.

Returns: Promise<{ id: string; }>


previous()

previous() => Promise<{ id: string; }>

Skip to the previous audio item in the playlist.

Returns: Promise<{ id: string; }>


seekTo(...)

seekTo(options: { position: number; }) => Promise<void>

Seek to a specific position in the currently playing audio item.

ParamType
options{ position: number; }

getDuration()

getDuration() => Promise<{ value: number; }>

Get the duration of the current audio item in seconds.

Returns: Promise<{ value: number; }>


getPosition()

getPosition() => Promise<{ value: number; }>

Get the current position of the audio item in seconds.

Returns: Promise<{ value: number; }>


addListener('update', ...)

addListener(eventName: 'update', listener: (result: { state: 'playing' | 'paused' | 'skip' | 'completed'; id: string; }) => void) => Promise<PluginListenerHandle>

Add an event listener for the update event. The listener should accept an event object containing the current state and id of the audio item.

ParamType
eventName'update'
listener(result: { state: 'playing' | 'paused' | 'skip' | 'completed'; id: string; }) => void

Returns: Promise<PluginListenerHandle>


Interfaces

StartOptions

Options for starting the audio player.

PropTypeDescription
itemsItem[]A list of audio items to be initialized in the audio player.

Item

Represents an audio item in the playlist.

PropTypeDescription
idstringThe unique identifier for the audio item.
titlestringThe title of the audio item, which is e.g. displayed in the notification player.
subtitlestringThe subtitle of the audio item, which is e.g. displayed in the notification player.
audioUristringThe local file URI of the audio file.
imageUristringThe local file URI of the image associated with the audio item.

PluginListenerHandle

PropType
remove() => Promise<void>