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

webaudiotag.js

v0.1.1

Published

Use AudioContext just like an `<audio>` tag.

Downloads

2

Readme

WebAudioTag.js

Use AudioContext just like an <audio> tag.

English | 简体中文

Getting Started

Install WebAudioTag.js

$ npm install webaudiotag.js

Use WebAudioTag.js in your project

import WebAudioTag from "WebAudioTag.js";

const webAudioTag = new WebAudioTag({
  src: "http://example.com/sound.mp3",
});
// or
// webAudioTag.src = "http://example.com/sound.mp3";

webAudioTag.play();

Config

| key | type | default | description | | ------------------ | ---------------------------------------------- | --------- | ------------------------------------------------------------------------------ | | config.src | string | "" | The url of audio | | config.volume | number | 1 | The volume of audio, must fall between 0 and 1 | | config.loop | boolean | false | If the value is true, the audio will loop playback automatically | | config.muted | boolean | false | Indicates whether the audio is muted | | config.extraNode | AudioNode[] | [] | The extra node that you want to connect to AudioContext | | config.fetchBuffer | (src: string) => Promise<ArrayBuffer | null>; | undefined | If you want to customize the request to get resources, you can use this config |

Attributes

| key | type | description | | -------------------- | ----------------------------- | ------------------------------------------------------------ | | instance.currentTime | number | Indicating the current playback time of the audio in seconds | | instance.duration | number | Readonly, indicating the duration of the audio in seconds | | instance.volume | number | See config.volume | | instance.src | string | See config.src | | instance.loop | boolean | See config.loop | | instance.muted | boolean | See config.muted | | instance.paused | boolean | Readonly, indicates whether the audio is paused | | instance.playState | "paused" | "playing" | Readonly, indicating the state of the audio | | instance.sourceNode | AudioBufferSourceNode | null | Readonly, current audio source node | | instance.ctx | AudioContext | Readonly, current AudioContext |

Methods

play

Begin playback of the audio.

(offset?: number) => Promise<boolean>;

pause

Pause playback of the audio.

() => Promise<boolean>;

on

Binds event-handling function.

(type: string, handler: Function) => void;

off

Unbind event-handler function.

(type: string, handler: Function) => void;

Events

Event handler is bound through on method, and unbinded through off method.

Example:

import WebAudioTag from "WebAudioTag.js";

const webAudioTag = new WebAudioTag();

const handler = (evt) => {};

webAudioTag.on("playStateChange", handler);

webAudioTag.off("playStateChange", handler);

See the following for the types of evt.

playStateChange

Event emmited after playState changed.

{
  type: "playStateChange";
  state: "paused" | "playing";
}

timeUpdate

Event emitted after currentTime changed.

{
  type: "timeUpdate";
  currentTime: number;
}

volumeChange

Event emitted after volume changed.

{
  type: "volumeChange";
  volume: number;
}

ended

Event emitted when the end of audio is reached.

{
  type: "ended";
}

progress

Event emitted when the audio data is downloading.

{
  type: "progress";
  src: string;
  percentage: number;
  chunked: number;
}

loaded

Event emitted when the audio data is loaded.

{
  type: "loaded";
}

error

Event emitted when an error occurred.

{
  type: "error";
  message: string;
  error: Error | null;
}