npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@smartcompanion/native-audio-player

v0.3.0

Published

Play Native Audio from a Capacitor App

Readme

native-audio-player

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

| Maintainer | GitHub | Social | | ----------- | ------------------------------------------- | --------------------------------------------------------------- | | Stefan Huber | stefanhuber | Linkedin |

Install

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

Configuration

| Platform | Configuration | | --- | --- | | iOS | Audio has to be added as Background Mode within Signing & Capabilities of the app, in order to keep audio playing in the background | | Android | The 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 manual testing.

| Demo App | Native Audio Player | |---|---| | Demo App Screen | Native Audio Player (Android) |

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.

| Param | Type | Description | | ------------- | ----------------------------------------------------- | -------------------------------------------- | | options | StartOptions | - 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.

| Param | Type | | ------------- | ---------------------------- | | 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.

| Param | Type | | ------------- | ---------------------------------- | | 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.

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

Returns: Promise<PluginListenerHandle>


Interfaces

StartOptions

Options for starting the audio player.

| Prop | Type | Description | | ----------- | ------------------- | ------------------------------------------------------------ | | items | Item[] | A list of audio items to be initialized in the audio player. |

Item

Represents an audio item in the playlist.

| Prop | Type | Description | | -------------- | ------------------- | ----------------------------------------------------------------------------------- | | id | string | The unique identifier for the audio item. | | title | string | The title of the audio item, which is e.g. displayed in the notification player. | | subtitle | string | The subtitle of the audio item, which is e.g. displayed in the notification player. | | audioUri | string | The local file URI of the audio file. | | imageUri | string | The local file URI of the image associated with the audio item. |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |