Giter Club home page Giter Club logo

node-omxplayer's Introduction

Node-Omxplayer

A library for controlling the Raspberry Pi omxplayer from Node.js.

Get Started

// Import the module.
var Omx = require('node-omxplayer');

// Create an instance of the player with the source.
var player = Omx('my-video.mp4');

// 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.

Installation

npm install node-omxplayer

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

API

Omx([source], [output], [loop], [initialVolume])

The constructor method, used to launch omxplayer with a source.

  • source (optional): The playback source, any audio or video file (or stream) that omxplayer is capable of playing. If left blank, the player will initialise and wait for a source to be added later with the newSource method.

  • output (optional): The audio output, if left blank will default to 'local', can be one of:

    • local - the analog output (3.5mm jack).
    • hdmi - the HDMI port audio output.
    • both - both of the above outputs.
  • 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.

player.newSource(source, [output], [loop], [initialVolume])

Starts playback of a new source, the arguments are identical to those of the Omx constructor method described above. If a file is currently playing, ends this playback and begins the new source.

player.play()

Resumes playback.

player.pause()

Pauses playback.

player.volUp()

Increases the volume.

player.volDown()

Decreases the volume.

player.fastFwd()

Fast forwards playback.

player.rewind()

Rewinds playback.

player.fwd30()

Skips playback forward by 30 seconds.

player.back30()

Skips playback backward by 30 seconds.

player.fwd600()

Skips playback forward by 600 seconds.

player.back600()

Skips playback backward by 600 seconds.

player.quit()

Quits the player.

player.subtitles()

Toggle subtitles.

player.info()

Provides info on the currently playing file.

player.incSpeed()

Increases playback speed.

player.decSpeed()

Decreases playback speed.

player.prevChapter()

Skips to previous chapter.

player.nextChapter()

Skips to next chapter.

player.prevAudio()

Skips to previous audio stream.

player.nextAudio()

Skips to next audio stream.

player.prevSubtitle()

Skips to previous subtitle stream.

player.nextSubtitle()

Skips to next subtitle stream.

player.decSubDelay()

Decrease subtitle delay by 250ms.

player.incSubDelay()

Increase subtitle delay by 250ms.

player.running

Boolean giving the playback status, true if the player is still active, false if it has ended or the player has quit.

Events

'close'

Fired when playback has finished.

'error'

Occurs when there is a problem with omxplayer. Includes a message with more information about the error.

Errors

'Output not allowed.'

Incorrect audio output type passed to the player, see Omx in the API section above. Can occur for the Omx constructor and the newSource method.

'Player is closed.'

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 newSource.

node-omxplayer's People

Contributors

amoriarty avatar ap0c avatar milasevicius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-omxplayer's Issues

Can't open volume

Hi, thanks for the package but it plays the video muted as default. volUp doesn't work for me. How can I help you to solve this? Thanks

adding position possibility omxplayer command --win

Hi,
Sorry I am not a programmer but a user. I have a big video installation with 30 raspberry remoted by OSC (with this : https://github.com/marsvaardig/osc-node ) It would be perfect if possible to remote the positon like with a for exemple "/win 0 0 960 540 /home/pi/videos... etc"

So how is it possible to add the --win command in theses two node? If possible ? And who could make it?

Thanks a lot
merci

Fabrice Aragno
Lausanne

The close event gets called multiple times

I listen to the close event to do something after a video is finished playing.

After first time adding a newSource and when the video is done the close event is called once (this is good).
But when I play a second video by adding newSource and when the video is done the close event is called twice.
And after a third video the close event is called three times.

Is there a reason this happens?

Audio play only for 1 sec then close immediately

Hello,
I'm facing an issue with node-omxplayer, I'm playing audio for 1 min then after that I'm closing the player and after 1 min again playing another audio but this time it plays only for 1sec and closes immediately.
please help me with this.

Thank you

error on launch

I've got a syntax error: Unexpected strict mode reserved word at line 5 in node-omxplayer/index.js.
Any idea ?

Thanks

[Question] Run node-omxplayer on mac?

Is there any way to run this player not on my raspberry but on my mac?
I would like to change something to the code and for testing purposes this would be ideal.

For now, if I run a javascript file, which uses the node-omxplayer it says I don't have the underlying OMX Player installed – which I actually don't. But I cannot figure out how to do that. Is it even possible to run it on a mac?

process immediately gets closed

Hi,

I've try to use your library with this piece of code:

var Omx = require('node-omxplayer');

var player = Omx('~/song.mp4');
player.on('close', function() {
  console.log('player closed!!!!');
});
player.on('error', function() {
  console.log('error happened!');
});

but the issue is it's immediately printing:
player closed!!!!
the player doesn't even open.

As a side note when I open omxplayer with exec it works well:

var exec = require('child_process').exec;
exec('omxplayer ~/song.mp4');

but with spawn (which your library uses) it again, immediately closing

var spawn = require('child_process').spawn;
var args = [ '~/song.mp4' ];
spawn('omxplayer', args);

I'm running this on latest raspbian, with nodejs v6.11.2

Have any suggestions how to solve it?
Thanks!

Feature Request: Make parameter "--blank" configurable

Hi,

I'm playing audio only and unfortunately, the current screen which shows important information is hidden due to a black fullscreen. The reason for this is the paramter --blank in line 38:

let args = [source, '-o', output, '--blank', osd ? '' : '--no-osd'];

Would it be possible to make this paramter configurable from outside?

extension request

I need a function to change the sound position to a specific location (forward and backward) based on the value of a clock, making the sound synchronized with a clock. Should it be possible to create a function to perform that function, and a specific method to read out the duration of a media file as an integer in ms?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.