Video Current time giving undefined

霸气de小男生 提交于 2021-02-11 08:26:16

问题


Hello I have dynamic videos which I tried to get the current video time but I seem to be getting undefined which i don't know why. I fire a function using on time update javascript event, however when i alert this var ok=$(e).attr('id'); i get the videos id but i dont know why when i try to get video current time i get undefined as value, these is my code dont know where i am getting it wrong.

      <script type='text/javascript'>
 function men(e){
    var ok = $(e).attr('id');
     var ol = $(e).attr('id');
    // alert(ol[0].currentTime); --- GIVES ME UNDEFINED
    $.ajax({
          type : 'POST',
           url : 'updatetime.php', 
          data :  {ok: ok, om: om}, 
            success : function(r)
           {

           }
    });
 }
 </script>

     <?php
$tl="channel";
$ooa="playing";
$played="played";
$timeline = mysqli_query($con, "SELECT * FROM plays WHERE streamers_type ='$tl' AND played !='$played' GROUP BY streamers_id ORDER BY id ASC") or die ();
    while($row = mysqli_fetch_array($timeline)) {
    $id = $row['id'];
    $file1 = $row['file1'];
    $video_name = $row['video_name'];
    $video_type = $row['video_type'];
    ?>  

  <video class="uopi spinal" id="<?php echo $id ?>"  style="height:180px; width:100%!important;" autoplay muted onended="run(this)" ontimeupdate="men(this)"><source src="plays/<?php echo $file1 ?>" type="<?php echo $video_type ?>"></video>

            <?php } ?>

回答1:


What you're doing is

var ol = $(e).attr('id');

ol[0].currentTime;

But .attr('id') returns a string, the ID of the element, which clearly doesn't have a currentTime property.

Try doing

$(e)[0].currentTime

instead



来源:https://stackoverflow.com/questions/41090232/video-current-time-giving-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!