javascript - Is it possible to show retrieved comments as elapsed time goes by? -


assuming there media(video) player on web page.

on flash,

<button name="test" onclick="alert(math.floor(jwplayer().getposition())+ 'secs elapsed!');">elapsed time</button> 

this code shows elapsed time of video

on html5,

<button name="test" onclick="alert(math.floor(document.getelementbyid('video').currenttime) + 'secs elapsed!');">elapsed time</button> 

this code shows elapsed time of video

i'm thinking of storing comments, , it's elapsed time database.

then automatically loads comments of particular video when user load page.
, displays each comment elapsed time goes by(my image pop-up)

is possible jquery(or javascript)? if how? can show me how implement easily.

if there comment this

  • at 5 secs "hello! 5 secs has past"
  • at 20 secs "hello! 20 secs has past"
  • at 35 secs "hello! 35 secs has past"
  • at 35 secs "hello! 35 secs has past. part2"
  • at 60 secs "hello! 35 secs has past"

update:

<!doctype html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta charset="utf-8"> <title>test</title>     <script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script> <meta name="keywords" content=""> <meta name="description" content="">  <script type="text/javascript"> jquery(document).ready(function () {     var comments = [{'time':'5','message':'hello! 5 secs has past'},{'time':'10','message':'hello! 10 secs has past'},{'time':'30','message':'hello! 15 secs has past'}];      $('#video').on('timeupdate',function(e){         showcomments(this.currenttime);     });      function showcomments(time){         var comments = findcomments(time);         $.each(comments,function(i,comment){             alert(comment.message);         });     }      function findcomments(time){         return $.grep(comments, function(item){           return item.time == time.tofixed();         });     } } </script>  </head>   <body>  <video id='video'       controls preload='none'        poster="http://media.w3.org/2010/05/sintel/poster.png">       <source id='mp4'         src="http://media.w3.org/2010/05/sintel/trailer.mp4"         type='video/mp4'>       <source id='webm'         src="http://media.w3.org/2010/05/sintel/trailer.webm"         type='video/webm'>       <source id='ogv'         src="http://media.w3.org/2010/05/sintel/trailer.ogv"         type='video/ogg'>       <p>your user agent not support html5 video element.</p>     </video>   </body></html> 

here's sample code can use starting point, using html5 javascript api

demo fiddle

//store comments in array objects time , message var comments = [{'time':'5','message':'hello! 5 secs has past'},{'time':'10','message':'hello! 10 secs has past'},{'time':'15','message':'hello! 15 secs has past'}];  //bind timeupdate event $('#video').on('timeupdate',function(e){     showcomments(this.currenttime); });  //show comments function showcomments(time){     var comments = findcomments(time);     $.each(comments,function(i,comment){         alert(comment.message);     }); }  //find comments current time function findcomments(time){     return $.grep(comments, function(item){       return item.time == time.tofixed(); //remove decimals check whole seconds     }); } 

you can read more video api here

also, should note timeupdate event fired @ different intervals in different browsers, check this question more info.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -