# node-mp3-player

> Use the browser Audio api to play mp3 files in node

Latest version **1.0.3** (published 2018-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-mp3-player
pnpm add node-mp3-player
yarn add node-mp3-player
bun add node-mp3-player
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-03-04 |
| First published | 2018-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 230.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Aram Drevekenin |
| Maintainers | imsnif |
| Keywords | mp3, electron, html5, browser-api, audio |

## Links

- npm: https://www.npmjs.com/package/node-mp3-player
- Repository: https://github.com/CommaSword/node-mp3-player
- Homepage: https://github.com/CommaSword/node-mp3-player#readme
- Issues: https://github.com/CommaSword/node-mp3-player/issues
- npm.io page: https://npm.io/package/node-mp3-player

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^3.2.1
- [JSONStream](https://npm.io/package/JSONStream.md) ^1.3.2
- [electron-spawn](https://npm.io/package/electron-spawn.md) ^5.0.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-03-04
- 1.0.2 — 2018-02-27
- 1.0.1 — 2018-02-25
- 1.0.0 — 2018-02-25

## README

# node-mp3-player

[![Coverage Status](https://coveralls.io/repos/github/CommaSword/node-mp3-player/badge.svg?branch=master)](https://coveralls.io/github/CommaSword/node-mp3-player?branch=master)
[![Build Status](https://travis-ci.org/CommaSword/node-mp3-player.svg?branch=master)](https://travis-ci.org/CommaSword/node-mp3-player)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

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.

```javascript
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
```javascript
const myFile = await Audio('/path/to/my/file')
```

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

### volume
```javascript
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
```javascript
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

---
_Source: https://npm.io/package/node-mp3-player · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
