Organizational Research By

Surprising Reserch Topic

Question: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 android_master
edited Sep 12, 2013
0 votes
48 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       if(time>video.seekable.start(i) && time         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 android_master
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       if(time>video.seekable.start(i) && time         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 android_master
edited Sep 12, 2013

...