@exodus/react-native-sound

中文文档
0.13.0-exodus.2发布于 2026/04/30MITTypeScriptCommonJS零依赖近 30 天下载 1.1万

在iOS、Android和Windows上播放声音剪辑的原生模块

中文使用文档
文档目录8 节
  1. 特性矩阵
  2. 安装
  3. 手动安装注释
  4. 辅助反应声
  5. Demo项目
  6. 玩家
  7. 基本用途
  8. 页:1

反应-原声

反应原生模块用于在iOS,Android,和Windows上播放声音剪辑.

'注:反应-内生-声不支持流出". 更多信息见#353. 当然,如果有人愿意的话,我们会欢迎公关.

特性矩阵

特性iOS系统机器人窗口
从应用程序捆绑中装入声音✓✓✓
从其他目录装入声音✓✓✓
从网络装入声音✓✓
播放声音✓✓✓
回放补全调用✓✓✓
暂停✓✓✓
继续✓✓✓
停下来✓✓✓
重设✓
释放资源✓✓✓
获取持续时间✓✓✓
获取频道数✓
获取/设置音量✓✓✓
获取系统音量✓✓
设定系统音量✓
获取/设置平板✓
获取/设置循环✓✓✓
获取/ 设定当前时间✓✓✓
设置速度✓✓

安装

首先从您的应用目录安装 npm 包 :

npm install react-native-sound --save

然后自动链接它使用 :

react-native link react-native-sound

手动安装注释

详情请参见维基百科 https://github.com/zmxv/resact-native-sound/wiki/ 安装

辅助反应声

  • 用于反应- 原声开发者 Gitter chat
  • 帮助使用反应- 原声 Gitter chat

Demo项目

https://github.com/zmxv/resact-native-sound-demo (英语)

玩家

https://github.com/benevbright/ react-native-相声-玩家观

基本用途

首先,你需要添加音频文件到您的项目中.

  • Android: 在目录下保存您的声音剪辑文件 android/app/src/main/res/raw。请注意,此目录中的文件必须是小写并下划线(例如我的 file name.mp3),子目录不被Android支持.
  • iOS: 打开 Xcode 并添加到工程中的声音文件( 右键单击工程并选择) Add Files to [PROJECTNAME](中文(简体) )
// Import the react-native-sound module
var Sound = require('react-native-sound');

// Enable playback in silence mode
Sound.setCategory('Playback');

// Load the sound file 'whoosh.mp3' from the app bundle
// See notes below about preloading sounds within initialization code below.
var whoosh = new Sound('whoosh.mp3', Sound.MAIN_BUNDLE, (error) => {
  if (error) {
    console.log('failed to load the sound', error);
    return;
  }
  // loaded successfully
  console.log('duration in seconds: ' + whoosh.getDuration() + 'number of channels: ' + whoosh.getNumberOfChannels());

  // Play the sound with an onEnd callback
  whoosh.play((success) => {
    if (success) {
      console.log('successfully finished playing');
    } else {
      console.log('playback failed due to audio decoding errors');
    }
  });
});

// Reduce the volume by half
whoosh.setVolume(0.5);

// Position the sound to the full right in a stereo field
whoosh.setPan(1);

// Loop indefinitely until stop() is called
whoosh.setNumberOfLoops(-1);

// Get properties of the player instance
console.log('volume: ' + whoosh.getVolume());
console.log('pan: ' + whoosh.getPan());
console.log('loops: ' + whoosh.getNumberOfLoops());

// Seek to a specific point in seconds
whoosh.setCurrentTime(2.5);

// Get the current playback point in seconds
whoosh.getCurrentTime((seconds) => console.log('at ' + seconds));

// Pause the sound
whoosh.pause();

// Stop the sound and rewind to the beginning
whoosh.stop(() => {
  // Note: If you want to play a sound after stopping and rewinding it,
  // it is important to call play() in a callback.
  whoosh.play();
});

// Release the audio player resource
whoosh.release();

页:1

版本与发布记录

@exodus/react-native-sound 共发布 4 个版本,首次发布于 2019/07/01;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.13.0-exodus.2latest2026/04/306 个月前
0.13.02021/04/135 年前
0.12.02021/04/135 年前
0.11.02019/07/017 年前

关于 @exodus/react-native-sound 的常见问题

@exodus/react-native-sound 是什么?

在iOS、Android和Windows上播放声音剪辑的原生模块

如何安装 @exodus/react-native-sound?

在项目目录运行 npm install @exodus/react-native-sound,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react-native(>=0.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@exodus/react-native-sound 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@exodus/react-native-sound 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@exodus/react-native-sound 可以商用吗?

@exodus/react-native-sound 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/react-native-sound 的下载量有多少?

根据 npm 官方下载统计,@exodus/react-native-sound 在 2026/10/14 – 2026/11/12 这 30 天内被下载 10,623 次,日均约 354 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/react-native-sound 还在维护吗?

最新版本 0.13.0-exodus.2 发布于 2026/04/30(6 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 1 个;首次发布于 2019/07/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。