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

237
Vistas
Display/ Hide Markers on Video based on current time Javascript

I am trying to implement a function that displays/ hides markers (could be subtitles, highlighted area) based on "timeUpdate" event which tracks current time.

My content source has multiple tracks. Based on current time, one or more tracks containing marker objects may be shown or hidden.

Here's the starter code. I only trying to implement an efficient algorithm which can be scalable in case number of tracks increase. Need suggestions on improvements

player.on('timeUpdate', function(event) {
    // currentTime (seconds, float) is exposed as event.data.currentTime
    var currentTime = event.data.currentTime;
    var time = convertTimeStamp(currentTime);
    // your algorithm will be called here with the currentTime as the argument
    handleAnnotations(time);
});

function handleAnnotations(currentTime) {  
    for (var i = 0; i < tracks.length; i++) {
        for (var j = 0; j < tracks[i].length; j++) {
            var currentAnnotationStartTime = convertTimeStamp(tracks[i][j].startTime);
            var currentAnnotationEndTime = convertTimeStamp(tracks[i][j].endTime);
            if (currentTime >= currentAnnotationStartTime && currentTime < currentAnnotationEndTime) {
                tracks[i][j].show;
            } else {
                tracks[i][j].hide;
            }
        }
    }
}

function convertTimeStamp(time) {
    var hours = Math.floor(time / 60 / 60);
    var minutes = Math.floor(time / 60);
    var seconds = Math.floor(time - minutes * 60);
    var hourValue = hours.toString().padStart(2, '0');
    var minuteValue = minutes.toString().padStart(2, '0');
    var secondValue = seconds.toString().padStart(2, '0');

    var mediaTime = `${hourValue}:${minuteValue}:${secondValue}`;
    return mediaTime;
}

Tracks are setup like this:

tracks =    [
                [annotation1, annotation2, annotationN...],
                [annotation1, annotation2, annotationN...], ... 
            ]

Where each annotation looks like:

{
     "startTime": timestamp,
     "endTime": timestamp,
     "show": fn,
     "hide": fn 
}
about 4 years ago · Juan Pablo Isaza
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