Skip to main content
Participant
May 28, 2023
Question

programatically define start of clip

  • May 28, 2023
  • 1 reply
  • 382 views

Hi.

I have a very simple problem for which I cannot find a solution:
How do I start a clip at a time that is defined by an expression, marker, control or script?
Ideally, I would like to somehow connect a marker to a clip so that the clip in the timeline moves with the marker.
One application would be to play a sound ("click") at a time defined by a marker (set to the point at which the finger hits the button).
My ideas: put a freeze frame in front of the clip, whose length can then be changed via a control variable/expression/script.

Or stretch the first frame of the clip to the length of time corresponding to the current time point.

The dream would be to have a method like "PlaySoundAtTime(sound, time)" or "StartClipAtTime(Layer, time)".

Or is there a general rule, why this can't be done?

Many thanks in advance

 

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
May 28, 2023

I think the closest you could come would be to enable time remapping for your clip layer, drag the right edge of the layer to extend the duration to the length of the comp, add a layer marker, and add this time remapping expression:

m = marker;
t = 0;
if (m.numKeys > 0){
  t = time - m.key(1).time;
}
t  > 0 ? 100 : 0

Then the clip will start playing at the marker. If you want it to be invisible until it starts playing, you could also add this opacity expression:

m = marker;
t = 0;
if (m.numKeys > 0){
  t = time - m.key(1).time;
}
t  > 0 ? 100 : 0

 

ghinAuthor
Participant
May 28, 2023

It works!

This solution has something ingenious in its simplicity!

The key point is to extend the duration. I did it by wrapping the clip in a pre-comp matching the length.

Thank your very much!

Dan Ebberts
Community Expert
Community Expert
May 28, 2023

Sorry, I pasted in the same expression twice. The first one (for time remapping) should have been like this:

m = marker;
t = 0;
if (m.numKeys > 0){
  t = Math.max(time - m.key(1).time, 0);
}
t