guerrerocarlos / chromecast-js

Chromecast Node.js module
162 stars 34 forks source link

Using player.getStatus() to update currentTime #7

Closed ddaf closed 9 years ago

ddaf commented 9 years ago

Hi there. I was wondering why this library is not using the player.getStatus() to update currentTime, instead of the cumbersome timePosition stuff. Here's an example from my fork where I use it just before device.seek to make sure I do a very precise seek.

ddaf commented 9 years ago

Might as well paste the code in for ease of reading:

Device.prototype.getStatus = function(callback) {
    var self = this;

    self.player.getStatus(function(err, status) {
        if (err) {
            console.log("getStatus error: %s", err.message);
        } else {
            callback(status);
        }
    });
};

Device.prototype.seek = function(seconds, callback) {
    var self = this;

    //Retrieve updated status just before seek
    self.getStatus(function(newStatus) {
        newCurrentTime = newStatus.currentTime + seconds;
        self.player.seek(newCurrentTime, function() {
            callback();
        });
    });
};