Organizational Research By

Surprising Reserch Topic

what is the and how is the html5 video on android - unexpected currentTime behavior


I have a video element on a page I'm loading on an Android tablet. There's a custom play button with the following event listener:

play_button.addEventListener("click", function ()
   { video.play(); tap_to_play.innerHTML = '';
     video.currentTime = offset;
     console.log(video.currentTime); }, false);

The first time I press the button, it will skip to the incorrect time. The logged currentTime will be 100, even though the video seems to skip to about 1400. If I press the button again when it's already playing, or pause and press the button again, it will go to the correct time. How can I get it to skip to the right location the first time?

asked Sep 13, 2013 in ANDROID by rajesh
edited Sep 12, 2013
0 votes
49 views



Related Hot Questions

2 Answers

0 votes

You could use the "seekable" TimeRange object to determine if the video file can actually be seeked to that position - otherwise it won't work. Here is a simple function that returns true if the desired time is within range:

function isSeekable(video, time) {
  if(video.seekable && video.seekable.length>0) { 
    for(var i=0, l=video.seekable.length; i<l; i++) {
      if(time>video.seekable.start(i) && time<video.seekable.end(i)) 
        return true;
    }
  }
  return false;
}

Check out the jsbin below for an example that works in Android 4.1. It will likely work in 3.1 too, but you will be hard pressed to find a solution that supports 2.3 or below:

answered Sep 13, 2013 by rajesh
edited Sep 12, 2013
0 votes

You could use the "seekable" TimeRange object to determine if the video file can actually be seeked to that position - otherwise it won't work. Here is a simple function that returns true if the desired time is within range:

function isSeekable(video, time) {
  if(video.seekable && video.seekable.length>0) { 
    for(var i=0, l=video.seekable.length; i<l; i++) {
      if(time>video.seekable.start(i) && time<video.seekable.end(i)) 
        return true;
    }
  }
  return false;
}

Check out the jsbin below for an example that works in Android 4.1. It will likely work in 3.1 too, but you will be hard pressed to find a solution that supports 2.3 or below:

answered Sep 13, 2013 by rajesh
edited Sep 12, 2013

...