• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to get current preview time with ExtendScript

New Here ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

Hi.

 

How to get current preview time with ExtendScript.

I want to get the current time of the preview like the expression "time," not time of the Current Time Indicator.

 

Thank you.

TOPICS
How to , Preview , Scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 22, 2020 Apr 22, 2020

An expression is evaluated at every frame and each time the expression is evaluated, the variable time gives you this point in time. There is no such thing for scripts, since they are not evaluated at each frame, but only once, when you execute them.

If you want to execute a script while a preview is playing, there is no way to know which frame is playing while the script is running (and if it is a long running script I am not even sure if playback pauses or not).

Votes

Translate

Translate
Advocate ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

Not quite sure what you mean by preview time, but if you're looking work area, then look at three 2 properties:

http://docs.aenhancers.com/items/compitem/#compitem-workareaduration

http://docs.aenhancers.com/items/compitem/#compitem-workareastart

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

An expression is evaluated at every frame and each time the expression is evaluated, the variable time gives you this point in time. There is no such thing for scripts, since they are not evaluated at each frame, but only once, when you execute them.

If you want to execute a script while a preview is playing, there is no way to know which frame is playing while the script is running (and if it is a long running script I am not even sure if playback pauses or not).

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

Agree with Mathias. Your idea doesn't make much sense to begin with, given how this stuff works. If you want to execute scripts and be aware of specific timing, you have to give them something to latch on to like markers, keyframes or the layer in- and out-points.

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 15, 2024 May 15, 2024

Copy link to clipboard

Copied

LATEST

Since there isn't a proper way to get the time during playback, I found this interesting workaround:

 

function getPlaybackTime () {
    // 1. Get the active comp
    var comp = app.project.activeItem;

    // 2. Read all markers in the composition (if there are any)
    function getCompMarkers () {
      var output = [];
      var markProp = comp.markerProperty;
      for (var i = 1; i <= markProp.numKeys; i++) {
        var marker = markProp.keyValue(i);
        marker['time'] = markProp.keyTime(i);
        output.push(marker);
      }

      return output;
    };

    // 3. Store the markers in a variable
    var origCompMarkers = getCompMarkers();

    // 4. Add a new marker (same as pressing the * key)
    var id = app.findMenuCommandId('Add Marker');
    app.executeCommand(id);

    // 5. Find the new marker we added and get its time and index
    function getNewMarker (origCompMarkers) {
        var newCompMarkers = getCompMarkers();
        var oldTimes = [];
        var newTimes = [];
        var diffTime = null;
        var diffIndex = null;
        for (var i = 0; i < origCompMarkers.length; i++) {
            oldTimes.push(origCompMarkers[i]['time']);
        }
        for (var j = 0; j < newCompMarkers.length; j++) {
            newTimes.push(newCompMarkers[j]['time']);
        }
        for (var h = 0; h < newTimes.length; h++) {
            if (oldTimes.indexOf(newTimes[h]) < 0) {
                diffTime = newTimes[h];
                diffIndex = h + 1;
            }
        }
        return {time: diffTime, index: diffIndex};
    };

    // 6. Store the new marker in a variable
    var newMarker = getNewMarker(origCompMarkers);

    // 7. Remove the new marker
    comp.markerProperty.removeKey(newMarker.index);

    // 8. Return the time of the new marker
    return newMarker.time;    
}

// 9. Enjoy :)
var previewTime = getPlaybackTime();
alert(previewTime);

I don't know why exactly, but it doesn't work if you preview only audio without video (if someone can figure it out it'll be awesome)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines