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 🙏

© 2026 – Pkg Stats / Ryan Hefner

musicplayer-api

v0.2.0

Published

Simple Audio API wrapper

Readme

musicplayer-api

musicplayer-api provides a simple way to implement a gapless music player using Web Audio API. It was originally meant to be used in environments such as electron but may eventually work in a browser.

Add it to your package with

npm install musicplayer-api

Example of usage

MusicPlayer = require('musicplayer-api').MusicPlayer

# The constructor automatically creates a new AudioContext
# and GainNode
player = new MusicPlayer()

# The addTrack is responsible of inserting songs in the
# playlist. It also asynchronously loads songs into memory
player.addTrack 'mymusic1.mp3'
player.addTrack 'mywav.wav'

player.play()

API Documentation

When used in node, musicplayer-api exports an object containing the MusicPlayer class. The same object is set to the mp global if used in a browser.

MusicPlayer class

Methods

player.setVolume( value )

Sets the volume to the specified value, where 0 is muted and 1 is default playback intensity.

player.getVolume()

Returns the playback intensity. Normally is 1.

player.toggleMuted()

Toggles between muted and unmuted state.

player.play()

Starts playing or resumes the playback of the current playlist.

player.stop()

Stops playing the current song in the playlist. When play is called again, the song is restarted from the beginning.

player.pause()

Suspends the playback of the current song.

player.playNext()

Skips to the next song in the playlist.

player.addTrack( path )

Adds the specified song to the playlist.

player.insertTrack( index, path )

Adds the specified song in the specified position of the playlist.

player.replaceTrack( index, path )

Replaces the specified track with another one.

player.removeTrack( index )

Removes the specified song from the playlist.

player.removeAllTracks()

Clears the playlist and stops the playback.

player.getSongDuration( index )

Returns the duration in seconds of the specifed song. If no index is provided, 0 is assumed.

player.getSongPosition()

Returns the playing position of the current song. Returns 0 if the playlist is empty or the song hasn't started yet.

player.setSongPosition( position )

Sets the playing position of the current song, expressed in seconds from the beginning. If the playback is stopped before the call, the player is started.

Events

onSongFinished

Called when a song has reached the end.

NOTE: Passes the song's path as an argument.

onPlaylistEnded

Called when the playlist has reached the end.

onPlayerStopeed

Called when the player is stopped programmatically.

onPlayerPaused

Called when the player is paused programmatically.

onTrackAdded

Called when a track is added to the playlist.

NOTE: Passes the track's path as an argument.

onTrackRemoved

Called when a track is removed from the playlist.

onTrackLoaded

Called when a track has finished loading its contents.

NOTE: Passes the track's path as an argument.

onVolumeChanged

Called when the volume is changed programmatically.

NOTE: Passes the volume's value as an argument.

onMuted

Called when the player is muted programmatically.

onUnmuted

Called when the player is unmuted programmatically.

Example

player = new MusicPlayer()
player.onVolumeChanged = (value) =>
  console.log 'Current volume: ' + value.toString()