M.O.S. Studios Posted August 28, 2010 Share Posted August 28, 2010 So I'm writing a javascript code that will control a quicktime video. To do this I'm using the quicktime plug in. One of the tools provided to me is variable that always contains the current time/position of the video. I want to write a script that will show that value in a text field. Does any know of a way I can update that value in real time?? thanks in advance Quote Link to comment Share on other sites More sharing options...
RussellReal Posted August 28, 2010 Share Posted August 28, 2010 there really isn't a way to do this "the right way", you know? if the quicktime plugin that you're utilizing gives you events to use for the time updating.. but if they're simple variables you can't check the variable with an event-based fashion. You will need to just update the times/positions every N miliseconds.. for example: function updateTime() { document.getElementById("positionHolder").innerHTML = QT.position; } setTimeout('updateTime'),500); Quote Link to comment Share on other sites More sharing options...
RussellReal Posted August 28, 2010 Share Posted August 28, 2010 there really isn't a way to do this "the right way", you know? if the quicktime plugin that you're utilizing gives you events to use for the time updating.. but if they're simple variables you can't check the variable with an event-based fashion. You will need to just update the times/positions every N miliseconds.. for example: function updateTime() { document.getElementById("positionHolder").innerHTML = QT.position; } setTimeout('updateTime'),500); SORRY I just realised I messed up a bit.. you'd need to constantly set the timeout.. you'd do this: function updateTime() { document.getElementById("positionHolder").innerHTML = QT.position; setTimeout('updateTime'),500); } setTimeout('updateTime'),500); Quote Link to comment Share on other sites More sharing options...
Omirion Posted August 29, 2010 Share Posted August 29, 2010 Since i consider this is not 2003 i whipped a little more efficient and friendlier code. function timeUpdate(positionVar,holder) { var that = this; this.intervalID = 0; //Declare interval id this.pos = positionVar; //The position var this.holderObj = holder; // The holder object IE div, p tag etc this.startUpdate = function () { that.intervalID = setInterval(function () { that.holderObj.innerHTML = that.pos }, 1000); } this.stopUpdate = function () { clearInterval(that.intervalID); } } You can create the new object timeUpdate like this var a = new timeUpdate(QT.positionVar,document.getElementById("holderDiv")); Or whatever your variables and holder object are. The you can start and stop the update like so. a.startUpdate() // to start a.stopUpdate() // to stop The object can be created in the global namespace like the example above. Or in your custom namespace if you have one. myNameSpace.update = new timeUpdate(); but the you need to refer to the var like so myNameSpace.update.start(update); If you have any questions please ask. If this has solved your problem please marked as solved. Quote Link to comment Share on other sites More sharing options...
M.O.S. Studios Posted September 6, 2010 Author Share Posted September 6, 2010 Thanks guys, I ended up figuring out the latter on my own, but I'm glad that this confirms this is the right way to do it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.