Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

431
Views
Cómo averiguar si algo comenzó, en una línea de tiempo

Estoy moviendo un cabezal de reproducción que se muestra a continuación con color naranja . Hay varios clips de audio que se muestran en colores verde , azul claro, azul oscuro y gris .

cosas paralelas

Mientras muevo el cabezal de reproducción, cuando se encuentra un clip de audio, lo reproduzco.

Considere este pseudo-código:

 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() } }

El código anterior es ineficiente. Dado que está llamando a play continuamente, si t es más grande que startTime de un clip.

Pero se prefiere llamar a play solo una vez, exactamente cuando t cruza startTime .

Me cuesta encontrar el mejor enfoque para detectar cuándo t cruza el tiempo de startTime de cada clip de audio. ¿Alguien tiene alguna sugerencia?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes cambiar tu pseudocódigo a algo como esto:

 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() }

Para evitar que se llame a esta devolución de llamada incluso cuando todo esté listo, necesitaría una función para dejar de escuchar los cambios de marco. Algo como:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!