html5 – 无法使用Jquery绑定视频事件

前端之家收集整理的这篇文章主要介绍了html5 – 无法使用Jquery绑定视频事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用视频标签并使用bind或live绑定它.在这两种情况下它都不起作用.Below是我的代码可能是我做错了什么并且无法捕获它.
<video width="videoWidth"
            height="videoHeight"
            poster="../Poster/poster.png"
            id="videoId"
            controls="controls"
            muted="true"    
            seeking="true"
            paused="true"   >

            <source src="../video/trailer.mp4" type="video/mp4"/>               
            <source src="../video/trailer.ogv" type="video/ogv"/>
            <source src="../video/trailer.webm" type="video/webm"/>
                Your browser does not support the video tag.
            </video>

这是用于绑定事件的JS文件包含.

$("#videoId").bind('ended',function() {
            alert("Entered");
        });

UPDATE

我正在更新以前的JS,现在它正在为所有视频事件工作.现在我坚持错误事件,事件将基于事件代码触发.可能我写错了,但是错误事件不能正常工作.我是JS

$(document).ready(function(){
        $("#videoId").bind('play',function() {
            alert("Play");
        });

        $("#videoId").bind('canplay',function() {
            alert("Can Play");
        });

        $("#videoId").bind('empited',function() {
            alert("Empited");
        });

        $("#videoId").bind('ended',function() {
            alert("Ended");
        });

        $("#videoId").bind('loadstart',function() {
            alert("Load Start");
        });

        $("#videoId").bind('pause',function() {
            alert("Pause");
        });

        $("#videoId").bind('playing',function() {
            alert("Playing");
        });

        $("#videoId").bind('progress',function() {
            alert("Progress");
        });

        $("#videoId").bind('suspend',function() {
            alert("Suspend");
        });

        $("#videoId").bind('volumechange',function() {
            alert("Volume");
        });

        $("#videoId").bind('waiting',function() {
            alert("waiting");
        });
        $("#videoId").bind('error',function(e,ui) {
            switch (e.target.error.code) {
             case e.target.error.MEDIA_ERR_ABORTED:
               alert('You aborted the video playback.');
               break;
             case e.target.error.MEDIA_ERR_NETWORK:
               alert('A network error caused the video download to fail part-way.');
               break;
             case e.target.error.MEDIA_ERR_DECODE:
               alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
               break;
             case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
               alert('The video could not be loaded,either because the server or network Failed or because the format is not supported.');
               break;
             default:
               alert('An unknown error occurred.');
               break;
           }
            //alert("Error Code : "+event.target.error.code);
        });

        });

在控制台我得到’获取’.

解决方法

这将警告视频元素上的错误对象中的所有对象
$("video").on("error",function(err) {
    for (var i in err.currentTarget.error) {
        alert(i + ": " + err.currentTarget.error[i]);
    }
});

猜你在找的HTML5相关文章