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

235
Views
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
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!