Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -35,7 +36,7 @@ interface NodeOmxPlayer extends Event {
*/
pause(): void;

/**
/**
* Increases the volume.
*/
volUp(): void;
Expand Down
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 ----- //

Expand All @@ -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;
Expand Down Expand Up @@ -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 ----- //
Expand Down