Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

435
Vistas
How to figure out if something started, on a timeline

I'm moving a play head shown below with orange color. There are multiple audio clips shown in green, light blue, dark blue, and gray colors.

Parallel things

While moving the play head, when an audio clip is encountered, I would play it.

Consider this pseudo-code:

playhead.callbackForEveryFrame(doStuffOnEveryFrame)

function doStuffOnEveryFrame(t) {
    // I intend to make sure all clips which should be playing, are actually play!
    if (clip_green.startTime < t) {
        clip_green.play()
    }
    if (clip_lightblue.startTime < t) {
        clip_lightblue.play()
    }
    if (clip_darkblue.startTime < t) {
        clip_darkblue.play()
    }
    if (clip_gray.startTime < t) {
        clip_gray.play()
    }
}

The above code is inefficient. Since it's calling play continuously, if t is larger than a clip's startTime.

But it's preferred to call play just once, exactly when t crosses the startTime.

I have a hard time finding the best approach to detect when t crosses the startTime of each audio clip. Does anybody have any suggestion?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can change your pseudo code to something like this:

let events = [clip_green, clip_lightblue, clip_darkblue, clip_gray].flatMap(clip => [
    { time: clip.start_time, do: () => clip.play() }, 
    { time: clip.end_time,   do: () => clip.stop() }
]).sort((a, b) => a.time - b.time)

playhead.callbackForEveryFrame(doStuffOnEveryFrame)

function doStuffOnEveryFrame(t) {
    while (events.length && events[0].time < t) events.shift().do()
}

To avoid that this callback is called even when all is done, you would need a function to stop listening to frame changes. Something like:

function doStuffOnEveryFrame(t) {
    while (events.length && events[0].time < t) events.shift().do()
    if (!events.length) playhead.stopCallbackForEveryFrame(doStuffOnEveryFrame);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda