From 46f21f1958d072dfae365e0aa529cf9b72b39c28 Mon Sep 17 00:00:00 2001 From: Jean Gravier Date: Thu, 3 Sep 2020 10:52:56 +0200 Subject: [PATCH 1/3] Added possibility to start video at specific timecode (omxplayer --pos option) --- index.d.ts | 5 +++-- index.js | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/index.d.ts b/index.d.ts index d5c0aa1..136429c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,8 +11,9 @@ interface NodeOmxPlayerStatic { * @param output (optional): The audio output, if left blank will default to 'local', can be one of: "local", "hdmi", "both" * @param loop (optional): Loop state, if set to true, will loop file if it is seekable. If left blank will default to false. * @param initialVolume (optional): The initial volume, omxplayer will start with this value (in millibels). If left blank will default to 0. + * @param startAt (optional): The start position of the video (in seconds). */ - (source?: String, output?: String, loop?: Boolean, initialVolume?: Number, showOsd?: Boolean): NodeOmxPlayer; + (source?: String, output?: String, loop?: Boolean, initialVolume?: Number, showOsd?: Boolean, startAt?: number): NodeOmxPlayer; } interface NodeOmxPlayer extends Event { @@ -35,7 +36,7 @@ interface NodeOmxPlayer extends Event { */ pause(): void; - /** + /** * Increases the volume. */ volUp(): void; diff --git a/index.js b/index.js index b9f0663..527ab8e 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ let spawn = require('child_process').spawn; let EventEmitter = require('events'); +const { start } = require('repl'); +const { time } = require('console'); // ----- Setup ----- // @@ -15,7 +17,7 @@ let ALLOWED_OUTPUTS = ['hdmi', 'local', 'both', 'alsa']; // ----- Functions ----- // // Creates an array of arguments to pass to omxplayer. -function buildArgs (source, givenOutput, loop, initialVolume, showOsd) { +function buildArgs (source, givenOutput, loop, initialVolume, showOsd, startAt) { let output = ''; if (givenOutput) { @@ -33,9 +35,13 @@ function buildArgs (source, givenOutput, loop, initialVolume, showOsd) { let osd = false; if (showOsd) { osd = showOsd; - } + } + + let args = [source, '-o', output, '--blank', osd ? '' : '--no-osd']; - let args = [source, '-o', output, '--blank', osd ? '' : '--no-osd']; + if (Number.isInteger(startAt) && startAt >= 0) { + args.push('--pos', startAt); + } // Handle the loop argument, if provided if (loop) { @@ -54,13 +60,13 @@ function buildArgs (source, givenOutput, loop, initialVolume, showOsd) { // ----- Omx Class ----- // -function Omx (source, output, loop, initialVolume, showOsd) { +function Omx (source, output, loop, initialVolume, showOsd, startAt) { // ----- Local Vars ----- // let omxplayer = new EventEmitter(); let player = null; - let open = false; + let open = false; // ----- Local Functions ----- // @@ -76,14 +82,14 @@ function Omx (source, output, loop, initialVolume, showOsd) { function emitError (message) { open = false; - omxplayer.emit('error', message); + // omxplayer.emit('error', message); } // Spawns the omxplayer process. - function spawnPlayer (src, out, loop, initialVolume, showOsd) { + function spawnPlayer (src, out, loop, initialVolume, showOsd, startAt) { - let args = buildArgs(src, out, loop, initialVolume, showOsd); + let args = buildArgs(src, out, loop, initialVolume, showOsd, startAt); console.log('args for omxplayer:', args); let omxProcess = spawn('omxplayer', args); open = true; @@ -105,7 +111,7 @@ function Omx (source, output, loop, initialVolume, showOsd) { if (open) { player.stdin.write(value); } else { - throw new Error('Player is closed.'); + // throw new Error('Player is closed.'); } } @@ -113,7 +119,7 @@ function Omx (source, output, loop, initialVolume, showOsd) { // ----- Setup ----- // if (source) { - player = spawnPlayer(source, output, loop, initialVolume, showOsd); + player = spawnPlayer(source, output, loop, initialVolume, showOsd, startAt); } // ----- Methods ----- // From 7b724346225c78389a83d4aa4874b46deb80e882 Mon Sep 17 00:00:00 2001 From: Jean Gravier Date: Thu, 3 Sep 2020 10:55:08 +0200 Subject: [PATCH 2/3] Removed debug comments --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 527ab8e..e521f49 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ function Omx (source, output, loop, initialVolume, showOsd, startAt) { function emitError (message) { open = false; - // omxplayer.emit('error', message); + omxplayer.emit('error', message); } @@ -111,7 +111,7 @@ function Omx (source, output, loop, initialVolume, showOsd, startAt) { if (open) { player.stdin.write(value); } else { - // throw new Error('Player is closed.'); + throw new Error('Player is closed.'); } } From ffb0d72de1aa34d23f786f40db9c579d89eb6405 Mon Sep 17 00:00:00 2001 From: Jean Gravier Date: Thu, 3 Sep 2020 10:56:15 +0200 Subject: [PATCH 3/3] Removed mistakenly imported modules. --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index e521f49..a5b67b7 100644 --- a/index.js +++ b/index.js @@ -4,8 +4,6 @@ let spawn = require('child_process').spawn; let EventEmitter = require('events'); -const { start } = require('repl'); -const { time } = require('console'); // ----- Setup ----- //