ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Play on hover (for more than n seconds) - Paly pause on a specified position.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Matteo Morando
Play on hover (for more than n seconds) - Paly pause on a specified position.
on Jul 22, 2019 at 10:41:23 am

Hi all,

I'm trying to do the following via expressions, It's a kind of automatic "play preview on hover" effect :

. Play a VideoLayer when it stops on a target position (in focus).
. Pause the VideoLayer when it leaves the target position (out of focus).
. Add two indipendent delays to both actions.
Start playing just if remains in focus for more than 40 frames (delayed play)
Pause 5 frames after moving out of focus (could even pause immediately)

I can play and pause (thanks to an old Dan's post), but can't figure out how to add the 2 indipendent delays...

I managed to have the play and pause working just using two experssions for now, but I'm sure there's a better way.

Expression 1 - On a Slider Control
Return the distance between Video and Target Layer, using world coordinates because the layers are parented.

Expression 2 - On the Time Remap value
Plays or pause the video if the Expression 1 returns 0 value (Video layer is on the target position).


As mentioned, this setup plays and pause, but can't delay the 2 actions indipendently.
I'm not really into code but enjoying hacking things together... hope that makes sense.

Any ideas wuold be extremely useful!
Thanks,

Matteo

// EXPRESSION 1 - On a Slider Control

P = thisComp.layer("MyVideoLayer");
T = thisComp.layer("TargetLayer");
PGlobal = P.toWorld(P.anchorPoint);
TGlobal = T.toWorld(T.anchorPoint);
d = sub(TGlobal, PGlobal);
d[0]

// EXPRESSION 2 - On the Time Remap of the Video Layer
s = effect("Slider Control")("Slider");
f = timeToFrames(time);
n = 0;

for (i = 0 ; i &lt; f; i++){
v = s.valueAtTime(framesToTime(i));
if (v == 0) n++;
}
framesToTime(n)




Return to posts index

Dan Ebberts
Re: Play on hover (for more than n seconds) - Paly pause on a specified position.
on Jul 22, 2019 at 9:12:11 pm

So what happens if you're hovering, move outside the hover area for 2 frames, and then move back in?

Dan



Return to posts index

Matteo Morando
Re: Play on hover (for more than n seconds) - Paly pause on a specified position.
on Jul 23, 2019 at 8:33:10 am

Hi Dan,

thanks for asking that's a good point.
Ideally the video should pause just if it leaves the target position for more than 5 frames.
If leaves and goes back to it in 2 frames, then it should ignore the movement and continue playing.

I guess another way to do it could be using position coordinates instead of time, the video pause just if the layer moves more than n pixels away from the target position.

What I'm trying to setup is a kind of Netflix UI rail, with a fixed focus area (target layer) and a line of tiles (video layers).
If a tile rest in focus position for more than n frames a preview start playing inside the tile frame.
When I "press" a button to move left or right in the rail (still using keyframes for that), the video preview stops playing, and I can browse the rail without video playing... hope it makes sense!

I'm trying to automate everything with expressions to speedup the workflow... and actually having fun and learning a lot from it ☺

Thanks,
Matteo


Return to posts index


Dan Ebberts
Re: Play on hover (for more than n seconds) - Paly pause on a specified position.
on Jul 25, 2019 at 9:33:55 pm

Sorry, it took a while to work out an algorithm for this. Using this as the slider expression:

threshold = 10;
P = thisComp.layer("MyVideoLayer");
T = thisComp.layer("TargetLayer");
PGlobal = P.toWorld(P.anchorPoint);
TGlobal = T.toWorld(T.anchorPoint);
d = length(TGlobal,PGlobal);
d < threshold ? 0 : 1

I think this does what you want for time remapping:


s = effect("Slider Control")("Slider");
fCur = timeToFrames(time);
firstTime = true;
hoverCount = 0;
outCount = 0;
playCount = 0;
for (i = 0; i <= fCur; i++){
v = s.valueAtTime(framesToTime(i));
if (v == 0){
firstTime = false;
outCount = 0;
hoverCount++;
if (hoverCount > 40){
outCount = 0;
playCount++;
}else{
outCount++;
}

}else{
if (! firstTime){
if(outCount > 5){
hoverCount = 0;
outCount++
}else{
playCount++;
outCount++;
hoverCount++;
}
}
}
}
framesToTime(playCount);


It's probably not perfect, but I think it's close.

Dan



Return to posts index

Matteo Morando
Re: Play on hover (for more than n seconds) - Paly pause on a specified position.
on Jul 26, 2019 at 3:36:29 pm

Works like a charm Dan!
You genius... I get the sense of it, but could've never been able to arrive even close.
That's so useful for so many things! ☺

You're an incredible resource for the community.

Many thanks again!
I'll do my best to keep the karma flowing.

Matteo


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]