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

omx-layers

v1.4.3

Published

Layer multiple omxplayer instances and control them via D-Bus

Downloads

1

Readme

omx-layers (Node.js)

An interface for Node.js allowing you to layer multiple omxplayer instances and control them in-process via the low-latency interprocess communication protocol, D-Bus.

You don't have to know anything about D-Bus. Just send commands using JavaScript, and the library handles the communication and logic internally.

How to Install

npm install omx-layers

Requirements

Remember that the omxplayer only works on the Raspberry Pi (and similar hardware?). Performance is great on the Pi 3.

omxplayer is installed by default on the "Raspbian with Desktop" version of Raspbian but if you have installed the "Lite" version (console only) then you might need to install it manually:

sudo apt-get install omxplayer

Examples

Single layer only

const omx = require('omx-layers');

let player = new omx({
	audioOutput: 'local',
	blackBackground: true,
	disableKeys: true,
	disableOnScreenDisplay: true,
});

Then play a clip like this:

player.open('myclip.mp4');

Multiple players, multiple layers

const omx = require('omx-layers');
let layers = [];
const numLayers = 2;

for (var i=0; i<numLayers; i++) {
	layers.push(
		new omx({
			audioOutput: 'local',
			blackBackground: true,
			disableKeys: true,
			disableOnScreenDisplay: true,
			layer: i
		})
	);
}

Find the clip with the layer you want, and play:

// Assume that an array has been set up with 2 layers.
// Let's say you wanted to play a clip on layer 2...
layer[1].open('foreground-clip.mp4');

How many layers can I open?

This seems to be very dependent on file sizes, resolutions and data rates for the video files.

If your player appears to quit video files without even trying to play them, you should try to increase the memory available to the GPU using sudo rasp-config > Advanced Options > Memory Split. 128MB should be good; 256MB might be better.

Options

  • audioOutput: 'hdmi' | 'local' | 'both'
  • blackBackground: boolean, false by default (careful enabling this when layering, or you might get strange intermittent screen blanking)
  • backgroundARGB: a hexadecimal colour value for Alpha, Red, Green, Blue - this is an alternative to using the default black. For example, if you want a full white background, use ffffffff and for full red use ffff0000, etc. This should only be applied to layer 1, not higher layers, in order to avoid flickering.
  • layer: 1-infinity (2 is probably enough!); if omitted then clips will automatically player on layer 0
  • disableOnScreenDisplay: boolean, false by default

Properties

Get duration of current track/movie in seconds

layer.getCurrentDuration();

Get position of current track/movie in seconds

layer.getCurrentPosition();

Get current position via D-Bus (if currently playing) in milliseconds.

Get volume as fraction of max (0.0 - 1.0)

layer.getCurrentVolume();

Methods

Open (play) a new clip

layer.open(path, holdMode = false) Open and start a clip at the given path. If you try to open another clip while one is already playing, this will be logged and ignored.

If holdMode===true, then clip will immediately pause on load and set opacity to 0 (waiting for your command).

Jump to point in file/seek relative to current position (-Inf to +Inf)

layer.seekRelative(milliseconds);

Jump to point in file/seek relative to start point (absolute)

layer.seekAbsolute(milliseconds);

Callbacks

onStart

It may take a few milliseconds for the clip to actually start playing after you call layer.open. The onStart callback is fired once the clip has been confirmed to have actually started playback.

onDone

This is called when the clip finishes playing (and the omxplayer instance stops/quits).

onProgress

The onProgress callback is called every second (by default) or however often you need (just set progressInterval in settings).

The callback sends a single object containing position, duration and playStatus (either playing, paused or error).

Example:

layer.onProgress = (info) => {
	console.log(`layer is at ${info.position} / ${info.duration}; currently ${info.status}`);
	// will output something like: layer is at 2500 / 10000; currently playing
}

Stop playing

layer.stop(); This seems to be the same thing as quitting! See https://github.com/popcornmix/omxplayer/issues/564

Quit omxplayer

layer.quit();

Pause omxplayer

layer.pause(); Pauses the clip; ignored if already paused.

Resume playing

layer.resume(); Resumes a clip if paused; ignored if already playing, and will generate an error in the logs if clip is already stopped/done but is essentially ignored.

Set volume

layer.setVolume(vol); Set volume to a fraction of the max volume (0.0 - 1.0)