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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-mp3

v0.1.2

Published

A minimalistic, flexible, fast 💥 react component for audio player

Downloads

2

Readme

React-mp3

This is a light blazingly fast, simple audio player for react. Here's a Demo

Installation

npm install --save react-mp3

Quickstart

Provider

Inside your root file App.tsx or App.jsx wrap around app with AudioProvider:

//ES6
import {AudioProvider} from "react-mp3";

//CommonJS
const {AudioProvider} = require("react-mp3");
  ...

export default function App () {
  return (
      <AudioProvider>
          //Rest of the code...
      </AudioProvider>
  )
}

AudioPlayer

Now import AudioPlayer from any of your component.

//ES6
import AudioPlayer from "react-mp3";

//CommonJS
const AudioPlayer = require("react-mp3");
//...

export default function Component () {
//...

return (
    <AudioPlayer src={[
        {
            title: 'Sample',
            artist: 'John Doe',
            url: 'https://filesamples.com/samples/audio/mp3/sample2.mp3',
            artwork: [
              {src: 'https://i.picsum.photos/id/516/200/300.jpg?hmac=hMEuvTcrLNhrMSSGnaRit4YgalzJJ66stNu-UT70DKw'}
              ]
        }
        ]}/>
)
} 

Hooks

Now you can use useAudio hook to change audio track, play, pause and much more from anywhere in your react app. Inside your component file Component.jsx:

import { useAudio } from "react-mp3";

export default function Component() {
  const {
    trackIndex,
    setTrackIndex,
    isPlaying,
    setIsPlaying,
    loop,
    setLoop,
    shuffle,
    setShuffle,
    volume,
    setVolume,
    //etc...
  } = useAudio();

  //....

}

Components

react-mp3 offers usable components.

LoopButton: a react button to loop audios.

NextButton: a button to go to next track. takes total number of audio as an argument.

PlayPauseButton: a button to go to play or pause current track.

PrevButton: a button to go to previous track. takes total number of audio as an argument.

ShuffleButton: a button to shuffle or unshuffle track.

TrackSlider: a range slider.

VolumeButton: a button to mute or unmute track.

Icons

LoopIcon, NextIcon, PlayIcon,PauseIcon, PrevIcon, ShuffleIcon, SpeakerIcon,SpeakerOffIcon.

Props

name | type | default | defination | -----| ----- | ----- | ----------- | src | { title: string; artist?: string; artwork?: { src: string;}[]; url: string;} | undefined | An array of audio urls, titles, artists, and artworks. | volume | number | 1 |Audio volume value between 0 and 1. | loop | "no-repeat \| "repeat-once" \| "repeat-all" | no-repeat | | shuffle | boolean | false | Whether or not to shuffle audios. The default value is false.| trackSliderClassName | string| undefined | If you want to change the style of the trackslider, use className.| showTime | boolean | true| Show the elapsed time and duration. The default value is true. | showVolume | boolean | true | Whether or not to show the volume button. The default value is true.| showPrev | boolean | true | Show the previous button. The default value is true.| showNext | boolean | true | Show the next button. The default value is true.| showShuffle | boolean | true | Show the shuffle button. The default value is true.| showCover | boolean | true |Showcase the title, artist name, and artwork. The default value is true. | trackSliderColor | string | #021C1E | Track sliders color when theres value| trackSliderBg | string | #6FB98F | Background color of the track slider| buttonColor | string | #000 | The color of the audio players buttons| buttonBgColor |string|#6fb98f | background color for buttons. Default is#6fb98f|currentTrackNum |number|0 | The current track number0as the opening track |onError |ReactEventHandler|null | Handle audio player related error withonErrorfunction |flexDirection | flex-direction CSS value |"row" |track slider and controls position. The default value isrow. | textColor |string | "#000" | The default value is #000. |

Improvements

Feel free to update, issue, improve this package. Fork the repo, make your changes and pull request.