视频播放结束后添加事件

在 Laravel 项目中,我有视频 vjs 播放器,如下代码所示:


<video

   id="my-video"

   class="video-js "

   controls 

   preload="auto"

   width="100%"

   height="auto"

   poster={{asset('images/'.$course->id.'.png')}}

   data-setup='{"fluid": true}'

   >

   <source src="{{asset('promos/'.$course->id.'.mp4')}}" />

   <source src="{{asset('promos/'.$course->id.'.mp4')}}" />

</video>

我想在播放视频结束后执行操作(将数据添加到服务器),我这样做了但不起作用:


<script>

    var vid = document.getElementById("my-video");

    vid.onended = function() {

    alert("The video has ended");

};

</script>

我该如何解决这个问题?


回首忆惘然
浏览 136回答 2
2回答

一只名叫tom的猫

我希望其中之一有帮助var options = {};var player = videojs('my-video', options, function onPlayerReady() {&nbsp; &nbsp; this.on('ended', function() {&nbsp; &nbsp; &nbsp; &nbsp; //do something here...&nbsp; &nbsp; });});或者var player = document.getElementById("my-video");player.addEventListener("ended", function() {&nbsp; //do something here...});

富国沪深

由于 Jsplayer 无法正常工作,我使用了 html5 视频播放器,它很好:-<video oncontextmenu="return false;" width="100%" height="auto" controls id="player"controls controlsList="nodownload" poster="{{asset('images/'.$course->id.'.png')}}"onended="alert('it is worked')">&nbsp; &nbsp; <source src="{{asset('promos/'.$course->id.'.mp4')}}" type="video/mp4">&nbsp; &nbsp; <source src="{{asset('promos/'.$course->id.'.m4v')}}" type="video/ogg"></video>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript