ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Play and Pause on markers

FAQ   •   VIEW ALL
 Play and Pause on markers on Oct 21, 2015 at 5:40:43 pm

I know this should be easy, but I'm trying to write a time remap expression freeze and play based on clip markers. I am surprised i couldn't find this already made. I will post it if I figure it out.

 Re: Play and Pause on markerson Oct 21, 2015 at 6:51:51 pm

I'm not sure what you have in mind exactly, but since expressions have no memory, your expression will need to calculate how much play time has occurred in the past by examining each marker previous to the current time.

Dan

 Re: Play and Pause on markerson Oct 21, 2015 at 7:42:23 pm

I understood this, and that is the part I'm trying to figure out. I wrote this after sending the post, but I still need to write something for calculating totaltime of the odd or even marker differences.

```try{ m = thisLayer.marker; i = m.nearestKey(time).index; if (m.nearestKey(time).time > time){ i--;} if (i &lt; 1) { i = 1}; if (i%2==1) {marker.key(i).time} else {totaltime} }catch(err){0}```

 Re: Play and Pause on markerson Oct 21, 2015 at 7:47:52 pm

Are the odd numbers play or pause?

Dan

 Re: Play and Pause on markerson Oct 21, 2015 at 7:50:55 pm

Currently The odd numbers are pause and I'm starting clip off frozen with marker off top.

 Re: Play and Pause on markerson Oct 21, 2015 at 7:49:41 pm

My last post didn't paste correctly. Something weird between Mac and PC text.

```try{ m = thisLayer.marker; i = m.nearestKey(time).index; if (m.nearestKey(time).time > time){ i--;} if (i &lt; 1) { i = 1}; if (i%2==1) {marker.key(i).time} else {totaltime} }catch(err){0}```

 Re: Play and Pause on markerson Oct 21, 2015 at 7:55:42 pm

If you're going to post code, don't preview your post, or all the < characters will get converted to html codes when you finally post it.

Dan

 Re: Play and Pause on markerson Oct 21, 2015 at 7:58:18 pm

Thanks. Was going crazy. < > test lol

 Re: Play and Pause on markerson Oct 21, 2015 at 8:43:20 pm

I think it will be something like this:

``` m = thisLayer.marker; if (m.numKeys > 0){ i = 1; segStart = 0; accum = 0; for (i = 1; i <= m.numKeys; i++){ if (m.key(i).time < time){ if (i%2){ accum += m.key(i).time - segStart; segStart = null; }else{ segStart = m.key(i).time; } }else{ break; } } if (segStart != null){ accum += time - segStart; } accum; }else time ```

Dan

 Re: Play and Pause on markerson Oct 21, 2015 at 8:50:22 pm

Looks good to me. Thanks, your biggest fan (probably not, since you are a rock star).

 Re: Play and Pause on markerson Oct 21, 2015 at 10:47:41 pm

One more thing I'm trying to figure out with another expression I'm using with the previous. I wrote the following expression to toggle an Effect Opacity on and off with keyframes. I can't figure out how to use easeOut to ramp the transition from 0 to 100 and back to 0 (on following keyframe).

```try{ m = thisLayer.marker; i = m.nearestKey(time).index; if (m.nearestKey(time).time > time){ i--;} if (i &lt; 1) { i = 1}; i%2*100 }catch(err){1}```

 Re: Play and Pause on markerson Oct 21, 2015 at 11:14:03 pm

This might work:

``` m = thisLayer.marker; easeTime = .25; if (m.numKeys > 0){ i = m.nearestKey(time).index; if (m.nearestKey(time).time > time) i--; if (i > 0){ t = time - m.key(i).time; if (i%2){ ease(t,0,easeTime,100,0); }else{ ease(t,0,easeTime,0,100); } }else{ 100; } }else{ 100; } ```

Dan

 Re: Play and Pause on markerson Oct 22, 2015 at 12:00:33 am

Worked perfectly. Thanks again.

 Re: Play and Pause on markerson Apr 3, 2019 at 8:55:07 pm

Bringing this oooold thread back up, I was wondering how Dan's expression up there needs to be changed to not play and stop at each marker, but always stop at each marker and only play for the duration of a marker (you know, when you split and drag it apart with ALT and click).

So basically the time between markers is the hold time, and the duration of each marker is play time. That way it's a bit more practical for time-remapping purposes, because moving a marker will always move its duration along with it.

 Re: Play and Pause on markerson Apr 3, 2019 at 11:44:12 pm

Something like this maybe:

``` m = thisLayer.marker; accum = 0; if (m.numKeys > 0){ n = m.nearestKey(time).index; if (m.nearestKey(time).time > time) n--; if (n > 0){ for (i = 1; i < n; i++){ accum += m.key(i).duration; } accum += Math.min(time-m.key(n).time,m.key(n).duration); } } accum ```

Dan