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..a5b67b7 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,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 +33,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 +58,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 ----- // @@ -81,9 +85,9 @@ function Omx (source, output, loop, initialVolume, showOsd) { } // 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; @@ -113,7 +117,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 ----- //