百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-native-audio-pro

> 编程语言
开源

此项目已归档,不再维护。谢谢。

193 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

此项目已归档,不再维护。谢谢。

React Native Audio Pro

[!WARNING]

⚠️ Archived / No Longer Maintained

Thank you for using react-native-audio-pro and for contributing feedback, fixes, and ideas. This project is now archived and no longer maintained. Feel free to fork this repository if you need changes for your own project.

Modern, background-capable audio playback for React Native — built for podcasts, audiobooks, and long-form media. Works out of the box with background playback, lock screen controls, and clean hooks-based state. Under the hood: Android uses Media3 (not old-school ExoPlayer), giving you up-to-date media session support without any of the legacy baggage. iOS uses AVFoundation, Apple's native audio engine for professional-grade media playback. Supports static remote files on iOS and Android.

Table of Contents

  • ✅️ Core Features
  • Add-On Features
  • ⚙️ Requirements
  • Installation
  • API Overview
  • ⚡️ React Hook
  • Types
  • ⚡️ useAudioPro Hook Example
  • API Usage Example
  • ⚠️ Event Listeners and React Lifecycle
  • Example App

✅ Core Features

These are fully supported, maintained features and the foundation of the library:

  • Remote Audio File Playback — Play MP3 and other audio files over HTTP(S)
  • Background Playback — Works with screen locked or app backgrounded
  • Lock Screen Controls — Media control support on Android and iOS
  • Artwork Support — Display album art on lock screen and media controls (JPEG, PNG, etc.)
  • Notification Center Integration — Android media session support
  • ⚙️ Imperative API — Functions like play, pause, resume, stop, etc.
  • Progress Tracking — Emits position/duration updates at configurable intervals
  • Volume Control — Real-time control of audio volume
  • Start Time Support — Begin playback from a specific position
  • HTTP Headers — Pass custom headers for audio and artwork URLs
  • Native Foundations — Powered by Media3 (Android) and AVFoundation (iOS)
  • Fully Typed API — First-class TypeScript support

Add-On Features

React Native Audio Pro also includes a few optional capabilities that support more advanced or specialized use cases. These are included in the library but may not receive the same level of maintenance priority as the core feature set.

  • Ambient Audio API — A simple secondary player for background or layered audio playback
  • Local Files via File Path — Supports full file:// paths (e.g. using react-native-fs)
  • Autoplay + Timers — Supports autoPlay and startTimeMs. For stop-at logic, use progress events in your app

⚙️ Requirements

  • TypeScript: 5.0 or higher
  • React Native: 0.72 or higher
  • iOS: iOS 17.0 or higher
  • Android: Android 8.0 (API 26) or higher

Installation

bash
npm install react-native-audio-pro

or

bash
yarn add react-native-audio-pro

iOS Installation

Install the CocoaPods dependencies:

bash
npx pod-install

Enable Background Modes

  1. Open your project settings in Xcode.
  2. Go to Signing & Capabilities.
  3. Add Background Modes and enable Audio, AirPlay, and Picture in Picture.

Android Installation

Note: This library requires Android 8.0 (API 26)+ and compileSdkVersion = 35 and targetSdkVersion = 35 to support the latest Media3 features. While Media3 APIs are supported from API 21+, our focus is on API 28+.

Gradle Configuration

In android/build.gradle:

gradle
buildscript {
    ext {
        minSdkVersion = 26
        compileSdkVersion = 35
        targetSdkVersion = 35
        // ...
    }
}

Expo Installation

Note: React Native Audio Pro requires a development build when using Expo, as it contains native code that cannot run in Expo Go.

  1. Install the required Expo package:
    bash
    npx expo install expo-build-properties
  2. For iOS, enable Background Modes in your app.json:
    json
    {
        "expo": {
            "ios": {
                "infoPlist": {
                    "UIBackgroundModes": ["audio"]
                }
            }
        }
    }
  3. For Android, update your plugins array in app.json:
    json
    plugins: [
      [
        "expo-build-properties",
        {
          "android": {
            "minSdkVersion": 26,
            "compileSdkVersion": 35,
            "targetSdkVersion": 35,
          },
        },
      ],
    ]
  4. The last step is to create a development build.

API Overview

React Native Audio Pro supports various audio file formats including MP3, AAC, and WAV, delivered over HTTPS.

Methods

Method Description Return Value
play(track: AudioProTrack, options?: AudioProPlayOptions) Loads and starts playing the specified track. void
pause() Pauses the current playback. void
resume() Resumes playback if paused. void
stop() Stops playback and resets position to 0 while keeping the current track loaded; use clear() to unload it. void
clear() Fully resets the player to the IDLE state and tears down the native player instance. void
seekTo(positionMs: number) Seeks to a specific position (in milliseconds). void
seekForward(amountMs?: number) Seeks forward by the specified milliseconds (default: 30 seconds). void
seekBack(amountMs?: number) Seeks backward by the specified milliseconds (default: 30 seconds). void
configure(options: AudioProSetupOptions) Sets playback options. Takes effect the next time play() is called. void
setProgressInterval(ms: number) Sets the PROGRESS event frequency (in ms). Takes effect the next time play() is called. void
getProgressInterval() Returns the current progress interval in milliseconds. number
getTimings() Returns the current playback position and total duration in milliseconds. { position: number, duration: number }
getState() Returns the current playback state. AudioProState
getPlayingTrack() Returns the current track, or null if none is loaded. AudioProTrack | null
setPlaybackSpeed(speed: number) Sets the playback speed rate (0.25 to 2.0). Normal speed is 1.0. void
getPlaybackSpeed() Returns the current playback speed rate. number
setVolume(volume: number) Sets the playback volume from 0.0 to 1.0. Does not affect the system volume. void
getVolume() Returns the current relative volume (0.0 to 1.0). number
getError() Returns the last error that occurred, or null if no error has occurred. AudioProPlaybackErrorPayload | null

⚡️ React Hook

The useAudioPro hook provides real-time access to the audio player state within your React components.

typescript
const { state, position, duration, playingTrack, playbackSpeed, volume, error } = useAudioPro();

To subscribe to only the specific piece of state your component needs (and avoid unnecessary re-renders), you can pass a selector function:

typescript
// Only re-renders when the playing track changes
const playingTrack = useAudioPro((s) => s.playingTrack);
Value Description Type
state Current playback state of the audio player. AudioProState
position Current playback position in milliseconds. number
duration Total duration of the current track in milliseconds. number
playingTrack Currently playing track object, or null if no track is loaded. AudioProTrack | null
playbackSpeed Current playback speed rate (0.25 to 2.0). number
volume Current playback volume (0.0 to 1.0). number
error Last error that occurred, or null if no error has occurred. AudioProPlaybackErrorPayload | null

Event Listeners

Method Description Return Value
addEventListener(callback: AudioProEventCallback) Listens for playback events (e.g., state changes, track ended, errors, progress). EmitterSubscription — call .remove() to unsubscribe.

Enums

AudioProState

State Description
IDLE The default state on app launch. Represents a player with no loaded track and fully cleared media sessions.
STOPPED Playback is stopped but the track remains loaded. Position is reset to 0, and media session controls remain visible.
LOADING A track is being loaded or buffered and is not yet ready for playback.
PLAYING A track is currently playing.
PAUSED Playback is paused at the current position.
ERROR An error occurred during playback. Check AudioPro.getError() for details.

AudioProEventType

Event Description
STATE_CHANGED Emitted when the player's state changes (e.g., from LOADING to PLAYING).
PROGRESS Emitted approximately once per second during playback with current position and duration.
TRACK_ENDED Emitted when a track completes playback naturally.
SEEK_COMPLETE Emitted when a seek operation completes. Payload includes triggeredBy (USER or SYSTEM).
PLAYBACK_SPEED_CHANGED Emitted when the playback speed is changed.
REMOTE_NEXT Emitted when the user presses the "Next" button on lock screen controls.
REMOTE_PREV Emitted when the user presses the "Previous" button on lock screen controls.
PLAYBACK_ERROR Emitted when a playback error occurs.

AudioProContentType

Type Description
MUSIC Optimized for music playback. Use for songs or music-heavy audio content. This is the default.
SPEECH Optimized for spoken word content. Use for podcasts, audiobooks, or speech-heavy content.

Ambient-specific event enums are documented in the Ambient Audio Guide.

Lock Screen Controls

Both iOS and Android support lock screen and notification controls for play/pause, seek, and track navigation (next/previous).

Configuration options:

typescript
AudioPro.configure({
	contentType: AudioProContentType.MUSIC,
	showNextPrevControls: true, // Hide next/previous buttons
	showSkipControls: false, // Show skip/seek forward/back buttons (default: true)
	skipIntervalMs: 30000, // Number of milliseconds for s

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言