A library for controlling the Raspberry Pi omxplayer from Node.js, now also supporting multiple displays, yay!
// Import the module.
import createVideoPlayer, { AudioOutput, VideoOutput } from 'omxplayer-node';
// Create an instance of the player with some global params set
const videoPlayer = createVideoPlayer({
display: VideoOutput.HDMI0,
audio: AudioOutput.jack,
});
// Open a file and set s'more params (these take precedency over the global ones)
videoPlayer.open({
source: 'test.mp4',
audio: AudioOutput.HDMI,
osd: true
});
// Control video/audio playback.
player.pause();
player.volUp();
player.quit();
Warning: If you quit node before quitting the player, there is a chance of a zombie process being created, which will persist until the current audio/video track ends.
npm install omxplayer-node
This module does not require any third party Node.js libraries, but does rely on omxplayer being installed. On the default version of Raspbian it is installed by default, but on the Lite version you will have to install it:
sudo apt-get install omxplayer
createVideoPlayer(globalParams: {audio?: AudioOutput, display?: VideoOutput, loop?: Boolean, initialVolume?: Number, osd?: Boolean}) => NodeOmxPlayer
This will initialize the player with some global parameters, so you don't have to set them every time you want to play a file.
-
audio
(optional): The audio output, if left blank will default to AudioOutput.jack, can be one of:AudioOutput.jack
- the analog output (3.5mm jack)AudioOutput.HDMI
- the HDMI port audio outputAudioOutput.both
- both of the above outputsAudioOutput.alsa
- use Alsa settings
-
display
(optional): The video output, if left blank will default to primary display, can be one of:AudioOutput.HDMI0
- the first HDMI portAudioOutput.HDMI1
- the second HDMI portAudioOutput.LCD
- the 7" LCD panel for RPi
-
loop
(optional): Loop state, if set to true, will loop file if it is seekable. If left blank will default to false.Warning: As stated above, if you quit node before quitting the player, a zombie process may be created. If this occurs when the loop option is in place, the
omxplayer
process may run indefinitely. -
initialVolume
(optional): The initial volume, omxplayer will start with this value (in millibels). If left blank will default to 0. -
osd
(optional): Whether to show OSD on top. Defaults to false.
After getting the player object like so: const player = createVideoPlayer(params)
, use the methods below to control
the playback:
player.open(params: {source: string, audio?: AudioOutput, display?:VideoOutput, loop?: Boolean, initialVolume?: Number , osd?: Boolean})
Starts playback of a new source, the arguments are identical to those of the createVideoPlayer
function
described above with addition of the required source
parameter. If a file is currently playing, ends this playback
and begins playing the new source.
Resumes playback.
Pauses playback.
Increases the volume.
Decreases the volume.
Fast forwards playback.
Rewinds playback.
Skips playback forward by 30 seconds.
Skips playback backward by 30 seconds.
Skips playback forward by 600 seconds.
Skips playback backward by 600 seconds.
Quits the player.
Toggle subtitles.
Provides info on the currently playing file.
Increases playback speed.
Decreases playback speed.
Skips to previous chapter.
Skips to next chapter.
Skips to previous audio stream.
Skips to next audio stream.
Skips to previous subtitle stream.
Skips to next subtitle stream.
Decrease subtitle delay by 250ms.
Increase subtitle delay by 250ms.
Boolean giving the playback status, true
if the player is still active, false
if it has ended or the player has quit.
Fired when playback has finished.
Occurs when there is a problem with omxplayer. Includes a message with more information about the error.
Incorrect audio output type passed to the player, see createVideoPlayer
in the API section above. Can occur when
creating the player or using the player.open
method.
An attempt has been made to send a command to the player after it has closed. Prevent this from happening by checking
if it is still running using the running
getter method. Can occur for any of the player methods except open
.