Jump to content

javascript instance update


M.O.S. Studios

Recommended Posts

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.