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

@eversoft-lk/music-js

v1.0.5

Published

music-js is a library that is used to play music in the browser

Downloads

1

Readme

Music-JS

Music-JS is a lightweight library that simplifies adding background music to your website using YouTube links or audio files. Built with TypeScript, this library provides an easy-to-use interface for integrating background music seamlessly into your web projects.

Table of Contents

Features

  • Easy Integration: Add background music to your website using YouTube links or audio files.

  • TypeScript Support: Built with TypeScript for robust type checking and development experience.

  • Wide Range of Support: Compatible with various frameworks such as React, Vue, Nuxt, Next, and Angular.

  • Customizable Controller: Override default controller elements with custom HTML elements.

Installation

To install Music-JS, use npm:

npm install @eversoft-lk/music-js

Note: CDN support is not available yet.

Usage

After installing the package, you can import and initialize the library in your project. Below are the steps and examples to get you started.

Importing the Library

First, you need to import MusicJS:

import MusicJS from "@eversoft-lk/music-js";

Initializing the Library

To initialize the library, use the MusicJS.init() function. This function takes a JavaScript object as a parameter with the following required keys:

  • method: Specifies the source type, either youtube or file.
  • src: Specifies the source URL(s). It can be a string or an array of strings.

Example 1: Using Audio Files

If you are using audio files as your source, set the method to "file" and provide the path(s) to the audio file(s) in the src key.

import MusicJS from "@eversoft-lk/music-js";

// Example with multiple audio files
MusicJS.init({
  method: "file",
  src: ["/song_file1.mp3", "/song_file2.mp3"],
});

// Example with a single audio file
MusicJS.init({
  method: "file",
  src: "/song_file1.mp3",
});

Example 2: Using YouTube Videos

If you are using YouTube videos as your source, set the method to "youtube" and provide the YouTube video link(s) in the src key.

import MusicJS from "@eversoft-lk/music-js";

// Example with multiple YouTube videos
MusicJS.init({
  method: "youtube",
  src: [
    "https://www.youtube.com/watch?v=video1",
    "https://www.youtube.com/watch?v=video2",
  ],
});

// Example with a single YouTube video
MusicJS.init({
  method: "youtube",
  src: "https://www.youtube.com/watch?v=video1",
});

Additional Options

The MusicJS.init() function also accepts optional parameters for further customization:

  • randomize: (boolean) Defaults to false. Set to true to shuffle songs to a random order before playing.

  • volume: (number) A value between 0 and 1 to adjust the volume.

Example 3: Randomizing Playback

import MusicJS from "@eversoft-lk/music-js";

MusicJS.init({
  method: "file",
  src: ["/song_file1.mp3", "/song_file2.mp3"],
  randomize: true,
});

Example 4: Adjusting Volume

import MusicJS from "@eversoft-lk/music-js";

MusicJS.init({
  method: "file",
  src: ["/song_file1.mp3", "/song_file1.mp3"],
  volume: 0.6,
});

Customizing the Music Controller

You can customize the default design of the music controller by passing custom controller elements using the elements option. Use ID or class selectors (prefixed with # or . respectively).

Example 5: Custom Controller Elements

import MusicJS from "@eversoft-lk/music-js";

MusicJS.init({
  method: "file",
  src: ["/song_file1.mp3", "/song_file2.mp3"],
  elements: {
    nextButton: ".music-js-next",
    prevButton: ".music-js-prev",
    playButton: ".music-js-play",
  }
});

If you define custom elements, the default elements will be overridden and disappear.

Summary

Music-JS makes it simple to add background music to your website, whether you prefer to use YouTube videos or audio files. By following the installation and usage instructions, you can easily integrate background music into your project with just a few lines of code.

License

MIT License