node-omx
v0.2.1
Published
Provide a nodejs interface for omxplayer (Raspberry Pi player). Support multiple file and loop.
Downloads
4
Maintainers
Readme
omxdirector
Nodejs module providing a simple interface to omxplayer.
Supports multiple files playing and loops. It's capable of seamless
loops if omxplayer
supports it natively. When omxplayer
doesn't
support loops, this module handles loops respawning omxplayer
process.
Installation
This module is a fork of alessandro-pezzato/omxdirector
To install
npm install omx-manager
Usage
Basic usage
var omx = require('omxdirector');
omx.play('video.avi');
Multiple files
omx.play(['video.mp4', 'anothervideo.mp4', 'foo.mp4'], {loop: true});
WARNING: at this time, multiple files playing is not supported by official omxplayer. If using with a fork version, you must enable native loop support (see below).
Options
- audioOutput
"local"
or"hdmi"
as-o
omxplayer argument. If not specified or"default"
is system default. - loop
true
to enable--loop
omxplayer argument. Default isfalse
. - layer
number
set the layer on which to reproduce the video. - win
object
set position of video window. You can set the x and y coordinates with the win object. For example to get the whole screen on a 1980 x 960 monitor you would use{x1: 0, y1: 0, x2: 1279, y2: 959}
(pixels start at 0). - randomOne
true
to play a single random video from all the resolved patterns. Default isfalse
WARNING: at this time, loop is not supported by official omxplayer. If using with a fork version, you must enable native loop support.
Example
omx.play('video.mp4', {loop: true}); // enables loop
omx.play('video.mp4', {audioOutput: 'local'}); // analog audio output
Native loop support
If you have a versione of omxplayer
supporting native loop with --loop
flag,
you can enable it by calling:
var omx = require('omxdirector').enableNativeLoop();
Loop fallback
If using with standard omxplayer, a fallback is provided: once a video is finished, another process of omxplayer is launched. It support multiple files and infinite loop. Although this works fine, native support is better because there's no gap between video.
Status
omx.getStatus()
Return an object with current status:
If process is not running:
{ loaded: false }
If process is running:
{
loaded: true,
videos: <Array>, // videos array passed to play(videos, options)
current: <String> // the path of the current playing video
settings: <Object>, // default settings or options object passed to play(videos, options)
playing: <boolean> // true if not paused, false if paused
}
Video directory
omx.setVideoDir(path);
Set where to look for videos. Useful when all videos are in the same directory.
Instead of this:
omx.play(['/home/pi/videos/foo.mp4', '/home/pi/videos/bar.mp4', '/home/pi/videos/asdasd.mp4']);
It's possible to use this shortcut:
omx.setVideoDir('/home/pi/videos/');
omx.play(['foo.mp4', 'bar.mp4', 'asdasd.mp4']);
Video suffix
omx.setVideoSuffix(suffix);
Set a suffix for videos. Useful when all videos share the same format.
Instead of this:
omx.play(['foo.mp4', 'bar.mp4', 'asdasd.mp4']);
It's possible to use this shortcut:
omx.setVideoSuffix('.mp4');
omx.play(['foo', 'bar', 'asdasd']);
Video patterns
Video paths can also be passed with shell-like syntax. For example:
omx.play('/home/pi/videos/*.mp4');
Will loop through all the mp4 files in /home/pi/videos.
Video patterns can be used in combination with the functions described earlier. The preceding is equal to:
omx.setVideoDir('/home/pi/videos');
omx.setVideoSuffix('.mp4');
omx.play('*');
You can also derive patterns in more complex ways.
omx.setVideoDir('/home/pi/videos');
omx.play(['!(*.txt)', '../moreVideos/foobar.mp4');
Will try to load every non-txt file in home/pi/videos
and foobar.mp4
from /home/pi/moreVideos/
.
Check out node-glob for an exhaustive list of supported patterns
Other methods
omx.pause(); // pause the video
omx.play(); // resume video playing
omx.stop(); // stop video playing and terminate omxplayer process
omx.isLoaded(); // return true if omxprocess is running
omx.isPlaying(); // return true if omxprocess is running and video is not paused
omx.volup(); // Increases the volume one notch
omx.voldown(); // Decreases the volume one notch
Events
omx.on('load', function(files, options){}); // video successfully loaded (omxprocess starts)
omx.on('play', function(){}); // when successfully started or resumed from pause
omx.on('changeVideo', function(newVideo){}); // when a new video in a loop starts
omx.on('pause', function(){}); // when successfully paused
omx.on('stop', function(){}); // when successfully stopped (omxplayer process ends)