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

mplayer

v2.1.0

Published

Node.js wrapper for mplayer

Downloads

109

Readme

Description

This module is a wrapper for mplayer started in slave mode (see documentation). It ensures that an instance of mplayer is always running in background ready for playback.

You need mplayer installed on your system for it to work properly!

See the Changelog section for all breaking changes which may cause issues if you've updated the module.

Installation

npm install mplayer

Usage

Start off with instantiating the client

var MPlayer = require('mplayer');

var player = new MPlayer();

You may want to pass in an object with options allowing for better debugging

  • verbose (Boolean): true, false - if set to true all player events will be logged to console
  • debug (Boolean): true, false - log mplayer stdout, stderr streams directly to console, along with everything written to stdin stream

or passing additional options to the spawned mplayer instance

  • args (String|Array): - list of additional parameters which will be passed to the command line mplayer instance (see mplayer manual for more details)

After this you will have access to all player methods and events. The player instance uses node's native EventEmitter for events management.

Methods

  • setOptions(< Object > options) - loops through the options object and uses mplayer set_property function to set them for the currently running instance

options is an object with one or more key value pairs, determining which parameters should be set, see the last section of slave mode documentation for the list of possible parameters and values

Example:

player.setOptions({
    cache: 128,
    cacheMin: 1
});
  • openFile(< String > file, [ Object ] options)

file is the location of the file you want to open either in your filesystem or on the web

options is an object passed to the setOptions method right before opening the file

Example:

player.openFile('/Users/noodny/Downloads/sample-video.avi');
  • openPlaylist(< String > file, [ Object ] options)

file is the location of the playlist file you want to open either in your filesystem or on the web

options is an object passed to the setOptions method right before opening the file

Example:

player.openPlaylist('http://www.radio.com/radio-stream.pls', {
    cache: 128,
    cacheMin: 1
});
  • play( )
  • pause( )
  • stop( )
  • seek(< Number > seconds) - seek to a specific second
  • seekPercent(< Number > percent ) - seek to a percent position of a file
  • volume(< Number > percent ) - set volume to a given percentage
  • mute( ) - toggle mute
  • fullscreen( ) - toggle fullscreen
  • hideSubtitles( )
  • showSubtitles( )
  • cycleSubtitles( ) - change to the next subtitles file in the file directory
  • speedUpSubtitles( )
  • slowDownSubtitles( )
  • adjustSubtitles(< Number > seconds) - adjust the subtitles timing by +/- seconds
  • adjustAudio(< Number > seconds) - adjust the audio timing by +/- seconds

Events

  • ready - triggered only once when mplayer process is started
  • time < Number > seconds - triggered every ~30ms
  • start - triggered once an asset playback has started
  • play - triggered when playback is resumed
  • pause - triggered when playback is paused
  • stop - triggered when an asset has finished playing
  • status < Object > status - triggered whenever player status changes The status object has the following properties:
{
    muted: Boolean,
    playing: Boolean,
    volume: Number, // percent
    duration: Number, // seconds
    fullscreen: Boolean,
    subtitles: Boolean,
    filename: String,
    title: String // currently playing stream title - valid only for radio streams
}

Example

The following example will set up a player instance, open a radio stream and set it's volume to 50% after 1 second, while logging the player status event output to the console:

var MPlayer = require('mplayer');

var player = new MPlayer();

player.on('start', console.log.bind(this, 'playback started'));
player.on('status', console.log);

player.openPlaylist('http://www.miastomuzyki.pl/n/rmfclassic.pls', {
    cache: 128,
    cacheMin: 1
});

setTimeout(player.volume.bind(player, 50), 1000);

Changelog

2.1.0

2.0.1

2.0.0

  • Change the open method to openFile and openPlaylist
  • Add verbose and debug constructor options

1.0.0

  • Emit play/pause events

0.0.3, 0.0.4

  • Remove stdout console logs

0.0.2

  • Proxy events to the object exported from module

TODO

  • Methods chaining
  • Throttle time event down to once per second
  • Defer methods resolving after actual player action