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

react-native-playback-controls

v0.2.1

Published

Control the system media UI (lock screen, Control Center, Android media notification, Bluetooth buttons) without playing audio yourself.

Readme

react-native-playback-controls

npm version license

Control the system media UI — the iOS lock screen / Control Center, the Android media notification, and Bluetooth / hardware media buttons — without this library ever playing any audio itself. It's a modern, New-Architecture, Turbo-Module replacement for react-native-music-control: you own the player (react-native-video, expo-audio, a native AVPlayer, anything), this library owns the system-level "now playing" surface.

  • Lock screen and Control Center controls on iOS
  • Media notification on Android
  • Bluetooth / hardware media button handling
  • New Architecture (Turbo Modules) only — no old-architecture fallback

Requirements

  • React Native with the New Architecture enabled (Turbo Modules + the codegen EventEmitter). Developed and tested against RN 0.83; older 0.8x versions with the New Architecture may work but aren't verified.
  • iOS 15.1+ (see PlaybackControls.podspec).
  • Android minSdkVersion 24+ / compileSdk 36 (see android/build.gradle).

Installation

yarn add react-native-playback-controls
# or: npm install react-native-playback-controls
cd ios && pod install

No other native setup is required beyond the platform sections below.

iOS setup

Controls only appear while your app is the system's active "Now Playing" app, which on iOS means an active AVAudioSession configured for .playback and actually producing audio. This library deliberately never touches AVAudioSession — your player (react-native-video, expo-audio, a native AVPlayer, …) owns it. If nothing is playing audio through an active session, MPNowPlayingInfoCenter won't surface your metadata on the lock screen or in Control Center, no matter how correctly you call this library's API.

Add background audio capability so command delivery keeps working while the app is backgrounded:

<!-- ios/YourApp/Info.plist -->
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Android setup

The required foreground-service permissions and manifest declarations are handled automatically. Two things remain the app's responsibility:

  • Request POST_NOTIFICATIONS at runtime on Android 13+ before calling startSession — the library deliberately never requests runtime permissions itself. Without it, the session still starts, but no notification is shown.
  • Call startSession while the app is in the foreground. Starting the underlying foreground service from the background throws (see Troubleshooting).

Also by design: when the user swipes the app away from Android's recents screen, the controls/notification are dismissed. Dead JS can't handle button presses, so there's nothing to keep them alive for.

Quick start

import { useEffect, useState } from 'react';
import {
  PlaybackControls,
  useRemoteCommand,
  type PlaybackSession,
} from 'react-native-playback-controls';

function NowPlaying() {
  const [session, setSession] = useState<PlaybackSession | null>(null);

  useEffect(() => {
    let active = true;
    PlaybackControls.startSession({
      commands: ['play', 'pause', 'toggle-play-pause', 'stop'],
    }).then((s) => {
      if (active) {
        setSession(s);
      }
    });
    return () => {
      active = false;
      session?.end();
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  useEffect(() => {
    session?.setNowPlaying({ title: 'Song title', artist: 'Artist name' });
    session?.setPlaybackState({ status: 'playing', positionSec: 0 });
  }, [session]);

  // iOS only delivers `toggle-play-pause`; Android always delivers
  // `play`/`pause`. Register all three to cover both platforms.
  useRemoteCommand(session, 'play', () => {
    /* resume your player */
  });
  useRemoteCommand(session, 'pause', () => {
    /* pause your player */
  });
  useRemoteCommand(session, 'toggle-play-pause', () => {
    /* toggle your player */
  });

  return null;
}

API reference

PlaybackControls.startSession(options) starts the single app-wide "now playing" session; the returned PlaybackSession exposes setNowPlaying, setPlaybackState, setCommands, and addCommandListener. The useRemoteCommand(session, command, handler) hook subscribes to a single command for the lifetime of a component.

const session = await PlaybackControls.startSession({
  commands: ['play', 'pause', 'toggle-play-pause', 'stop'],
});

session.setNowPlaying({ title: 'Song title', artist: 'Artist name' });
session.setPlaybackState({ status: 'playing', positionSec: 0 });

Full method signatures, error codes, type definitions (CommandConfig, NowPlayingMetadata, PlaybackState, ...), and iOS/Android behavior differences (e.g. setNowPlaying merge-vs-replace semantics, how toggle-play-pause is delivered) are documented in docs/API.md.

Troubleshooting

Controls don't show on iOS. The app isn't the current "Now Playing" app. Confirm you have an active AVAudioSession (category .playback) with audio actually flowing, and that UIBackgroundModes: audio is set if you need controls while backgrounded.

No notification on Android 13+. Request the POST_NOTIFICATIONS runtime permission before calling startSession — the library does not request it for you.

session-already-active. A session is already running. Call end() on the existing PlaybackSession handle before starting a new one.

foreground-required. startSession was called while the app was backgrounded on Android. Only start a session from a foreground-initiated action.

Controls disappear after swiping the app away (Android). By design — see the "app swiped away" behavior in docs/API.md. There is no revival mechanism in this version.

Buttons do nothing after a Metro reload. This should not happen — the native module tears itself down via invalidate on JS context invalidation. If you can reproduce it, please file an issue with repro steps.

Roadmap

Features intentionally deferred out of v1 (ratings/feedback commands, custom notification buttons, shuffle/repeat, queue metadata, CarPlay/Android Auto browsing, and more) are tracked in docs/IDEAS.md.

Contributing

License

MIT


Made with create-react-native-library