@clxrity/react-audio
Version:
A simple audio player for React
81 lines (59 loc) • 4.21 kB
Markdown
# @clxrity/react-audio <img src="https://clxrityy.github.io/react-audio/apple-touch-icon.png" width="32px" height="32px" style="display:inline-block;" />
#### A react audio player component library.
[](https://github.com/clxrityy/react-audio/blob/main/LICENSE) [](https://www.npmjs.org/package/@clxrity/react-audio)
[](https://www.npmjs.org/package/@clxrity/react-audio) [](https://github.com/clxrityy/react-audio/actions/workflows/main.yml)
---
[](https://github.com/clxrityy/react-audio/blob/main/.nvmrc)
#### Peer Dependencies:
[](https://www.npmjs.com/package/react) [](https://www.npmjs.com/package/react-dom)
```zsh
npm i @clxrity/react-audio
```
```zsh
pnpm add @clxrity/react-audio
```
```zsh
yarn add @clxrity/react-audio
```
---
[
](https://clxrityy.github.io/react-audio/?story=home--readme)
[](https://clxrityy.github.io/react-audio/?story=documentation--changelog)
---
## Dynamic import example with Next.js
```tsx
'use client' // (REQUIRED)
import dynamic from 'next/dynamic'
import '@clxrity/react-audio/index.css' // (optional) import the styles
/**
* You can also import the CSS within your `globals.css` or `index.css` file like so:
* ```css
* @import "@clxrity/react-audio/index.css";
* ```
*/
const Player = dynamic(
() => import('@clxrity/react-audio').then((mod) => mod.Player),
{ ssr: false }
)
export default function Component() {
const track = {
src: '/loop.wav', // (REQUIRED) audio file path (public/loop.wav)
title: 'Loop',
artist: {
name: 'Clxrity',
url: 'https://wav.clxrity.xyz',
},
}
return <Player track={track} showTrackInfo={true} />
}
```
---
> - **Note:** You may use external URLs for the **src** property for components such as [`<Player />`](https://clxrityy.github.io/react-audio/??story=player--default) and [`<ShufflePlayer />`](https://clxrityy.github.io/react-audio/?story=shuffleplayer--default) components and experience no CORS issues, as the audio files are fetched and played by the client-side.
> - However, for components such as [`<Waveform />`](https://clxrityy.github.io/react-audio/?story=waveform--default) and [`<Spectrogram />`](https://clxrityy.github.io/react-audio/?story=spectrogram--default) components, the CORS origins must be set correctly on the server-side to avoid CORS issues. This is only applicable when using external URLs for the **src** property.
> - For example, if using files served from firebase storage, set the CORS origins to **`*`** to allow all origins to access the files.
> - [Firebase CORS Configuration](https://firebase.google.com/docs/storage/web/download-files#cors_configuration)