omxplayer-controller-node
Version:
Raspberry Pi omxplayer controll using dbus-native
316 lines (312 loc) • 8.95 kB
JavaScript
var events = require("events");
var omx_dbus = require("./lib/omxp_dbus");
//TODO fix this to make user independent
omx_dbus.on("changeStatus", function (status) {
var diff = status.duration - status.pos;
if (diff > 2000000 && diff < 7000000) {
omx_dbus.emit("aboutToFinish");
}
});
/**
* Open OmxPlayer, with the given parameter
*
* @path {String} The file or folder path
* @options {Object} The options available
*/
module.exports = omx_dbus;
module.exports.open = omx_dbus.openPlayer;
module.exports.quit = omx_dbus.quitPlayer;
module.exports.playPause = function (cb) {
//checked
omx_dbus.method("PlayPause", function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.pause = function (cb) {
//checked IDEM playPause
omx_dbus.method("Pause", function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.stop = function (cb) {
//checked IDEM Stop
omx_dbus.method("Stop", function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.getStatus = function (cb) {
//checked
omx_dbus.propertyRead("PlaybackStatus", function (err, status) {
cb(err, status);
});
};
module.exports.getDuration = function (cb) {
//checked
omx_dbus.propertyRead("Duration", function (err, status) {
cb(err, status);
});
};
module.exports.getPosition = function (cb) {
//checked
omx_dbus.propertyRead("Position", function (err, pos) {
cb(err, Math.round(pos / 10000));
});
};
module.exports.setPosition = function (pos, cb) {
//checked
pos = pos * 10000;
omx_dbus.method("SetPosition", ["/not/used", pos], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.seek = function (offset, cb) {
//checked
omx_dbus.method("Seek", [offset], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.listAudio = function (cb) {
//checked
omx_dbus.method("ListAudio", function (err, audioStreams) {
cb(err, audioStreams);
});
};
module.exports.selectAudio = function (audioStreamId, cb) {
//checked
omx_dbus.method("SelectAudio", [audioStreamId], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.nextAudio = function (cb) {
//checked
omx_dbus.method("Action", [7], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.listAudio = function (cb) {
//checked
omx_dbus.method("ListAudio", function (err, audioStreams) {
cb(err, audioStreams);
});
};
module.exports.selectAudio = function (audioStreamId, cb) {
//checked
omx_dbus.method("SelectAudio", [audioStreamId], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.nextAudio = function (cb) {
//checked
omx_dbus.method("Action", [7], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.previousAudio = function (cb) {
//checked
omx_dbus.method("Action", [6], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.getVolume = function (cb) {
//checked
omx_dbus.propertyRead("Volume", function (err, vol) {
cb(err, vol);
});
};
module.exports.getVolume = function (cb) {
//checked
omx_dbus.propertyRead("Volume", function (err, vol) {
cb(err, vol);
});
};
module.exports.setVolume = function (vol, cb) {
//checked *not oficially but Working
if (vol <= 1.0 && vol >= 0.0) {
omx_dbus.setVolume(vol, function (err, resp) {
return typeof cb === "function" ? cb(err, resp) : {};
});
} else {
return cb(new Error("Volume should be between 0.0 - 1.0"));
}
};
module.exports.volumeUp = function (cb) {
//checked
omx_dbus.method("Action", [18], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.volumeDown = function (cb) {
//checked
omx_dbus.method("Action", [17], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.listSubtitles = function (cb) {
//checked
omx_dbus.method("ListSubtitles", function (err, subtitleStreams) {
cb(err, subtitleStreams);
});
};
module.exports.listSubtitles = function (cb) {
//checked
omx_dbus.method("ListSubtitles", function (err, subtitleStreams) {
cb(err, subtitleStreams);
});
};
module.exports.toggleSubtitles = function (cb) {
//checked not tested (I have no subtitles)
omx_dbus.method("Action", [12], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.nextSubtitle = function (cb) {
//checked
omx_dbus.method("Action", [11], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.nextSubtitle = function (cb) {
//checked
omx_dbus.method("Action", [11], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.previousSubtitle = function (cb) {
//checked
omx_dbus.method("Action", [10], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.previousSubtitle = function (cb) {
//checked
omx_dbus.method("Action", [10], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.hideSubtitles = function (cb) {
//checked not tested (I have no subtitles)
omx_dbus.method("Action", [30], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.showSubtitles = function (cb) {
//checked not tested (I have no subtitles)
omx_dbus.method("Action", [31], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.setAlpha = function (alpha, cb) {
//checked
if (alpha >= 0 && alpha <= 255) {
omx_dbus.method("SetAlpha", ["/not/used", alpha], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
} else {
return cb(new Error("Alpha should be between 0 - 255"));
}
};
module.exports.setVideoPos = function (x1, y1, x2, y2, cb) {
//checked
var vidPos =
x1.toString() +
" " +
y1.toString() +
" " +
x2.toString() +
" " +
y2.toString();
omx_dbus.method("VideoPos", ["/not/used", vidPos], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.setVideoCropPos = function (x1, y1, x2, y2, cb) {
//checked
var vidPos =
x1.toString() +
" " +
y1.toString() +
" " +
x2.toString() +
" " +
y2.toString();
omx_dbus.method("SetVideoCropPos", ["/not/used", vidPos], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.setAspectMode = function (aspect, cb) {
//checked
var available_aspects = ["letterbox", "fill", "stretch", "default"];
if (available_aspects.indexOf(aspect) > -1) {
omx_dbus.method("SetAspectMode", ["/not/used", aspect], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
} else {
throw new Error(
"Not an available aspect use one of: " + available_aspects.join(",")
);
}
};
module.exports.hideVideo = function (cb) {
//checked
omx_dbus.method("Action", [28], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.unhideVideo = function (cb) {
//checked
omx_dbus.method("Action", [29], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.getSource = function (cb) {
//checked
omx_dbus.propertyRead("GetSource", function (err, vol) {
cb(err, vol);
});
};
module.exports.getMinRate = function (cb) {
//checked
omx_dbus.propertyRead("MinimumRate", function (err, vol) {
cb(err, vol);
});
};
module.exports.getMaxRate = function (cb) {
//checked
omx_dbus.propertyRead("MaximumRate", function (err, vol) {
cb(err, vol);
});
};
module.exports.reduceRate = function (cb) {
//checked
omx_dbus.method("Action", [1], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
module.exports.increaceRate = function (cb) {
//checked
omx_dbus.method("Action", [2], function (err) {
return typeof cb === "function" ? cb(err) : {};
});
};
//=========================Not working functions
// module.exports.quit = function(cb) { //not working
// omx_dbus.method('Quit', function(err) {
// return typeof cb === 'function' ? cb(err) : {};
// });
// };
// module.exports.mute = function(cb) { //not working
// omx_dbus.method('Mute', function(err) {
// cb(err);
// });
// };
// module.exports.getRate = function(cb) { //not working
// omx_dbus.propertyRead('Rate', function(err, vol) {
// cb(err, vol);
// });
// };
// module.exports.play = function(cb) { //not working
// omx_dbus.method('Play', function(err) {
// return typeof cb === 'function' ? cb(err) : {};
// });
// };
//=========================EN OF NOT WORKING FUNCTIONS