HTML5 视频获取当前时间不适用于媒体事件 javascript addEventListener



我试图在视频播放时显示当前持续时间(打印当前时间直播(。

我确实阅读了Kurt Van den Branden关于检测HTML5视频元素是否正在播放的答案,但无济于事

我最终想将当前时间值携带到 PHP 变量$currenttime以下是我当前的代码

<html> 
<head>  
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Html5 media events</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head> 
<body >
<div id="output"></div>
<video id="myVideo" width="320" height="176" controls>
    <source src="http://action.news/videos/Britney%20Spears%20-%20Overprotected%20(2009)%20Full%20HD%201080p_60%20fps.mp4" type="video/mp4">
</video>
<script>
    var media = document.getElementById('myVideo');
    // Playing event
    var isPlaying = function(e) {
    #$("#output").html("Playing event triggered");
    };
      // durationchange
    var isdurationchange = function(e) {
        $("#output").html(vid.currentTime);

    };
    media.addEventListener("playing", isPlaying, false);   
    media.addEventListener("durationchange", isdurationchange, true);    
</script>   
</body> 
</html>

你应该可以这样携带它,专业人士会帮助你语法

 document.write("<a href=/time.htm?currentTime='.media.addEventListener("timeupdate", isdurationchange, true).'>link</a>;); 

侦听事件timeupdate而不是durationchange(也更正您的错别字错误,如@Jeto评论中提到的(

var media = document.getElementById('myVideo');
    // Playing event
    var isPlaying = function(e) {
    $("#output").html("Playing event triggered");
    };
      // durationchange
    var isdurationchange = function(e) {
        $("#output").html(media.currentTime);
    };
    media.addEventListener("playing", isPlaying, false);   
 //   media.addEventListener("durationchange", isdurationchange, true);   
 
  media.addEventListener("timeupdate", isdurationchange, true);                 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="output"></div>
<video id="myVideo" width="320" height="176" controls>
    <source src="http://fiber.westnet.ca:81/videos/Britney%20Spears%20-%20Overprotected.mp4" type="video/mp4">
</video>

最新更新