0

I want to take a particular value of time (given in seconds by html5 htmlmedia timerange.end) and check where it falls in a list of times I already have that looks like this

00:00:00.00
00:00:22.00
00:01:21.00
00:01:36.00
00:01:51.00
00:02:06.00
00:02:21.00
00:02:36.00

I have these values hard-coded in a text file server side from the capture program.

I'd like to check and see in between which two values it (video_time) lies, and from there change the src in an iframe if the src does not correspond to the time slot, there are n times in the list above and corresponding n-1 slots in between them, the src will be named like /Slide0.html through /Slide[n-1].html.

So far I've created some logic to check the time, place holder logic to change the src of the iframe if the value is >15 sec and some callBack to call things periodically.

[EDIT: removed some irrelevant stuff]

Here is the problem:

function category() {
    var played_ob =video_time_played() ;
    if ( played_ob  > 0 )
      var played_num = played_ob;
    else
     var played_num = 0;
    var tes = 15;
    if ( played_num > tes)
     document.getElementsByTagName("iframe")[0].src="/static/Slide1.html";
    else
     console.log ("meh");
};

Above I wish to check in which timerange it falls and set the proper iframe; this is what I need help with. What I would like to do is as follows:

/* PSEUDOCODE OF WHAT I WISH TO ACHIEVE BUT DONT KNOW HOW TO DO IT ENTIRELY.*/
 function category (){
     var time_spent = video_time_played_so_far_in_seconds(); 
       /* this part i dont know, especially how to generate the list from a text file serverside */
     categories_list = [list of consecutive times i showed above in HH:MM:SS.00]
      
     var which_category = function check_in_between_which_two_times_var_lies () {
        /***********  i DONT know how to code this part either, *******/
        the_category_found_as_an_integer_between_0=>n-1 = ? 
        var category = the_category_found_as_an_integer_between_0=>n-1 ;
        return category  ;
       }
      
     function which_new_src (which_category) {
      /* code to select new src */
         var new_src = "/static/Slide"+which_category".html";
         return new_src;
     }
    
     function change_src_of_iframe () {
         var relevant_iframe = document.getElementsByTagName("iframe")[0];
         
         change_src_of_iframe () {
         var new_src = which_new_src(which_category);
         relevant_iframe..src= new_src ;
         }
      
2
  • what's the question? WHat works and what doesn't work? You haven't identified a problem. Creating a demo in jsfiddle.net would help
    – charlietfl
    Commented Mar 10, 2013 at 13:32
  • 1
    You will need to parse the lines into a format so that the times are comparable, then you could apply a binary search on your array. See this answer
    – Bergi
    Commented Mar 10, 2013 at 16:00

1 Answer 1

1

this is what i ended up doing:

to convert the ordered array with HH:MM:SS to ordered seconds array:

function to_seconds (capture){
console.log(capture.length);
var clean = new Array() ;
for ( var i = 0, len = capture.length; i<len; i++ ) {
     if (capture[i] ) 
       clean.push(capture[i]);
    } 

console.log(clean.length);
var ready = clean ;

var times = new Array() ;
   for ( var i = 0, len = ready.length; i<len; i++ ) {

       var obj =  ready[i].split(':'); 
       var seconds =obj[0]*3600+obj[1]*60+obj[2]*1;
       times.push(seconds) ;
   }
console.log(times.length);
return times ; 
}

and then to check the slot in which the time played so far falls,

function find_category_number (time,list) {
 var number = 0;
 for ( var i = 0, len = list.length; i<len; i++ ) {
 if ( time > list[i] && time < list[i+1] )
    number= i;
 }

return number ;
}

and finally to generate a new src value:

function find_new_src (category_number) {
var src = "/static/Slide"+category_number+".html" ;
return src ;
}

and that was what i needed to do most, guess breaking down the problem into small modular parts kind of helped, i was trying to do all that logic at the same time, and my brain froze.

Not the answer you're looking for? Browse other questions tagged or ask your own question.