@gfazioli/mantine-audio

中文文档
1.1.10发布于 2026/11/09MITTypeScriptESM + CJS零依赖近 30 天下载 2.9万

A Mantine-native audio player for React with waveform visualization and live spectrum analyzer, built on Web Audio API. Compound component API + headless useAudio hook.

原始使用文档
文档目录5 节
  1. Overview
  2. Features
  3. Installation
  4. Usage
  5. Sponsor

Mantine Audio Component

Mantine Audio

mantine-audio at a glance, refreshed daily: commits, releases, stars, issues and pull requests, a year of commit activity, the weekly rhythm, languages, latest commits and releases, contributors
Made with glancecard · refreshed daily

Overview

This component is built on top of the Mantine library.

The Mantine Audio component is a Mantine-native audio player for React with waveform visualisation and a live spectrum analyser, built on the Web Audio API. It ships as three layers in a single package: a polished default <Audio /> with four variants, a fully composable compound API (ten sub-components you can reorder and restyle), and a fully headless useAudio hook to build 100% custom UIs.

Features

  • 🎧 Drop-in player — <Audio src="…" /> and you have a styled, accessible audio player
  • 🧩 Compound API — 10 sub-components (Audio.PlayButton, Audio.Timeline, Audio.Waveform, Audio.Spectrum, Audio.VolumeSlider, Audio.SpeedControl, …) reorderable and re-styleable
  • 🪝 Headless useAudio hook — 16 state values + 12 actions for fully custom UIs
  • 🌊 Waveform visualisation — peaks decoded via Web Audio + click/drag to seek, 60fps playhead tracking via RAF
  • 🎚️ Live spectrum analyser — AnalyserNode driven, solid or gradient bars, optional mirror
  • 🔀 Multiple <source> support — sources={[…]} for codec / format / media-query fallbacks + fallbackSrc for runtime errors
  • 🎛️ 5 sizes × 4 variants — xs/sm/md/lg/xl × overlay/minimal/floating/bordered (all CSS-driven via data attributes)
  • 🌅 asBackground preset — turn the same player into a hero / section ambient track in one line
  • 🎚️ Scrub-with-sound — optional scrubSound lets the user hear snippets while dragging (Audacity / iTunes style)
  • ⌨️ Keyboard shortcuts — Space, J/K/L, ←/→, ↑/↓, M, > / <
  • 🎨 Full Styles API — classNames, styles, vars, unstyled, theme-aware out of the box
  • 📦 TypeScript — strict types, every prop documented

[!note]

→ Demo and Documentation → More Mantine Components

Installation

npm install @gfazioli/mantine-audio

or

yarn add @gfazioli/mantine-audio

After installation import package styles at the root of your application:

import '@gfazioli/mantine-audio/styles.css';

Usage

import { Audio } from '@gfazioli/mantine-audio';

function Demo() {
  return <Audio src="/track.mp3" />;
}

Compound layout with waveform on top and a custom skip button:

<Audio src="/track.mp3">
  <Audio.Waveform height={80} />
  <Audio.Controls>
    <Audio.SkipButton seconds={-15} />
    <Audio.PlayButton />
    <Audio.SkipButton seconds={15} />
    <Audio.Timeline />
    <Audio.TimeDisplay />
    <Audio.MuteButton />
    <Audio.VolumeSlider />
    <Audio.SpeedControl />
  </Audio.Controls>
</Audio>

Headless usage with the useAudio hook:

import { useAudio } from '@gfazioli/mantine-audio';

function MyPlayer() {
  const { playing, currentTime, duration, peaks, analyser, toggle, audioRef } = useAudio({
    src: '/track.mp3',
  });

  return (
    <div>
      <audio ref={audioRef} crossOrigin="anonymous" />
      <button onClick={toggle}>{playing ? 'Pause' : 'Play'}</button>
      <span>{currentTime.toFixed(1)} / {duration.toFixed(1)}</span>
    </div>
  );
}

Sponsor

Your support helps me:

  • Keep the project actively maintained with timely bug fixes and security updates
  • Add new features, improve performance, and refine the developer experience
  • Expand test coverage and documentation for smoother adoption
  • Ensure long‑term sustainability without relying on ad hoc free time
  • Prioritize community requests and roadmap items that matter most

Open source thrives when those who benefit can give back—even a small monthly contribution makes a real difference. Sponsorships help cover maintenance time, infrastructure, and the countless invisible tasks that keep a project healthy.

Your help truly matters.

💚 Become a sponsor today and help me keep this project reliable, up‑to‑date, and growing for everyone.

版本与发布记录

@gfazioli/mantine-audio 共发布 18 个版本,首次发布于 2026/05/20;过去 12 个月发布了 18 个版本。

版本发布日期距今
1.1.10latest2026/11/096 天前
1.1.92026/11/069 天前
1.1.82026/10/2621 天前
1.1.72026/10/2224 天前
1.1.62026/10/131 个月前
1.1.52026/10/101 个月前

关于 @gfazioli/mantine-audio 的常见问题

@gfazioli/mantine-audio 是什么?

A Mantine-native audio player for React with waveform visualization and live spectrum analyzer, built on Web Audio API. Compound component API + headless useAudio hook.

如何安装 @gfazioli/mantine-audio?

在项目目录运行 npm install @gfazioli/mantine-audio,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.x || ^19.x)、react-dom(^18.x || ^19.x)、@mantine/core(>=9.0.0)、@mantine/hooks(>=9.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gfazioli/mantine-audio 支持 TypeScript 吗?

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

@gfazioli/mantine-audio 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gfazioli/mantine-audio 可以商用吗?

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

@gfazioli/mantine-audio 的下载量有多少?

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

@gfazioli/mantine-audio 还在维护吗?

最新版本 1.1.10 发布于 2026/11/09(6 天前);至今共发布 18 个版本,其中过去 12 个月发布了 18 个;首次发布于 2026/05/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。