Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

432
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda