Socket
Socket
Sign inDemoInstall

node-mp3-player

Package Overview
Dependencies
116
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-mp3-player

Use the browser Audio api to play mp3 files in node


Version published
Weekly downloads
23
increased by53.33%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

node-mp3-player

Coverage Status Build Status JavaScript Style Guide

Use the browser Audio api to play mp3 files in node. Browser api brought to you by electron (specifically electron-spawn) The motivation being this should be more cross-platform friendly. API is still early stages and supports the basic stuff, we're open to new functionality being requested and/or contributed.

usage

Require the createAudio method and use it to get the Audio constructor. The Audio constructor has more or less the same API as the browser Audio global. See the API section for specific quircks.

Please note that the createAudio method instantiates an electron child_process in order to access the the browser API. Calling it multiple times will instantiate multiple electron processes. This is probably not what you want. You probably want to create multiple files using the Audio pseudo constructor. Though if multiple electron instances is your thing, knock your socks off.

const { createAudio } = require('node-mp3-player')
const Audio = createAudio();

(async () => {
  const myFile = await Audio(`${__dirname}/mp3/foo.mp3`)
  await myFile.volume(0.5)
  const currentVolume = await myFile.volume() // 0.5
  await myFile.loop()
  await myFile.stop()
})()

API

Should be the same as the browser Audio api, except it returns promises and thus uses traditional functions rather than getters/setters.

constructor

const myFile = await Audio('/path/to/my/file')

play / stop

const myFile = await Audio('/path/to/my/file')
await myFile.play() // plays the file
await myFile.stop() // stops the file

volume

const myFile = await Audio('/path/to/my/file')
await myFile.volume(0.5) // changes the volume, similar to the browser myFile.volume = 0.5

loop

const myFile = await Audio('/path/to/my/file')
await myFile.loop(true) // loops the file similar to the browser myFile.loop = true
await myFile.loop(false) // unloops the file similar to the browser myFile.loop = false

license

MIT

Keywords

FAQs

Last updated on 04 Mar 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc