Jump to content
GreenSock

croucho

call back for a parent's seek()?

Go to solution Solved by Carl,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Greetings folks!

 

I've been digging through the documentation but am worried I might be missing something (or what I'm looking for isn't supported.)

 

Here's my situation:

  • I have a main TimelineMax that I append all kinds of tweens and sub-timelines to.
  • A few of these tweens are in place to simply start/stop audio tracks at a particular location.
  • When I call seek() on the main timeline, all the tweens adjust to the correct spot, but I need to adjust the currentTime on the audio tracks and call play/pause as necessary based on the Tween's isActive().

I can't seem to find a way to receive a callback when the main timeline's position is tweeked via a seek() call.

 

I've seen other threads where folks try to control position of videos manually with a tween (manipulating currentTime) but that is resulting is crazy ugly audio issues for me.

 

Is there anyone out there that can help me wrap my head around this?

Help me Obi-Wan Kenobi, you're my only hope!

 

-Croucho

 

CodePen Example Setup  (wait for the audio to start 5 seconds in, click the blue square. I want to stop the audio from playing so that it will re-trigger correctly when it's tween becomes active).

See the Pen pyrQLo?editors=1111 by croucho (@croucho) on CodePen

  • Like 1
Link to comment
Share on other sites

  • Solution

Hi and welcome to the GreenSock forums,

 

Thanks for the demo. TimelineLite/Max are not at all designed for audio / video sequencing so there is not really a clean "out of the box" solution that I can think of.

 

You could put anUpdate callback on the parent timeline and run some conditional logic on every update to determine if certain sounds should be stop playing, start playing from the beginning or start playing from a specific time, but I think that would be a bit messy and wasteful.

 

You may want to explore using callbacks at specific times to start each sound. So if you have 3 sounds you might do something like

 

1: create an array of objects for each sound

var sounds = [
{sound:sound1, time:1},
{sound:sound2, time:2.5},
{sound:sound3, time:4},
]

2: loop through that array an add callbacks to the timeline

tl.call(startSound, [sound1], scope, 1);
tl.call(startSound, [sound2], scope, 2.5);
tl.call(startSound, [sound3], scope, 4);

3: create a function that starts a sound

function startSound(sound) {
  //play sound
}

The above steps will allow a sound to play when the timeline plays normally and the playhead reaches each added call()

 

In addition you might want to create your own custom seek method that 

  • seeks the timeline to a specific time
  • based on the desired seek time you calculate which sounds need to stop and which sounds need to play and from where.

so assuming all sounds had a duration of 1 second and you wanted to seek to a time of 3 you would loop through your sounds array and run some logic that would:

  • tell sound1 to pause
  • tell sound2 to play from 0.5
  • tell sound3 to pause 

 

Hopefully that points you in the right direction. Unfortunately its not the type of thing I can build out for you.

Perhaps someone else has some other ideas. 

  • Like 4
Link to comment
Share on other sites

Thanks for getting back Carl :)

I'm going to take your advice and write a manager that will be notified from the main timeline when I anticipate a seek has occurred. The manager will then do the work of playing/pausing/seeking the various sounds.

 

Thanks again for getting back so quick.

 

-Croucho

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×