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

@dalanke/react-audio-player

v1.0.1

Published

HTML5 audio tag based music player wrap in react component

Downloads

9

Readme

React audio player

This a React component based on HTML5 <audio> tag. It provides basic music player features as well as responsive design. Could be a reference for who want to create their own music player in React.

image

Click here for mobile screen shot

This component has been used in project Teatime music, visit github repo to see detail: https://github.com/Dalanke/youtube_audio_API

Live demo can be access here: https://stayhome-ui.herokuapp.com/

Project structure

.
├── README.md
├── example
├── lib
├── package-lock.json
├── package.json
├── rollup.config.js
└── src
  • Source code located in src
  • Example are created by create-react-app, use cd example && npm start to start in local host (might need to link the package first)

Usage

Import

npm install @dalanke/react-audio-player 
import { Player } from '@dalanke/react-audio-player';

...
// in render()/return()
<Player
  playlist={this.state.playlist}
  shufflePlaylist={this.shufflePlaylist}
  removeFromPlaylist={this.removeFromPlaylist}
  hide={this.state.hidePlayer}
/>

Component props

  • playlist: the playlist pass into player. Playlist should be a object contains name, description and musics. musics is an array store muisc information, src will be passed into <audio src="">. See example playlist below:

    const testPlaylist = {
    name: 'Temp Playlist',
    description: '',
    musics: [
      {
        src: 'https://stayhome-api.herokuapp.com/stream?id=HdQCWXh3XXU',
        title: 'STYX HELIX ',
        author: 'Re:ゼロから始める異世界生活 ED1',
        thumbnail: 'https://i.ytimg.com/vi/HdQCWXh3XXU/maxresdefault.jpg',
      },
      {
        src: 'https://stayhome-api.herokuapp.com/stream?id=E8S2IHiuWZA',
        title: 'Kizuna Music キズナミュージック♪ [Piano+Sheet]',
        author: 'Poppin Party',
        thumbnail: '',
      },
      ],
    }
  • shufflePlaylist: the function shuffle playlist(shuffle musics array), example code:

    shufflePlaylist = (callback) => {
      const copyList = [...this.state.playlist.musics];
      for (let i = copyList.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [copyList[i], copyList[j]] = [copyList[j], copyList[i]];
      }
    
      // we need reset the current index after shuffle, pass the call back in here
      this.setState({ playlist: { ...this.state.playlist, musics: copyList } }, callback);
    }
  • removeFromPlaylist: remove a song from playlist, used in playlist button, example code:

    removeFromPlaylist = (index) => {
      const copyList = [...this.state.playlist.musics];
      copyList.splice(index, 1);
      this.setState({ playlist: { ...this.state.playlist, musics: copyList } });
    }
  • hide: boolean, hide the player or not

Development

  • This component is styled with react-bootstrap
  • Each botton are separated into child component.
  • The Player component create a ref to <audio> tag, to access the <audio> element, use this.audio.current, see MDN docs for more info about <audio>: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio