视频播放结束后添加事件
Add Event after video play is ended
在 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>
我该如何解决这个问题?
我希望其中之一对您有所帮助
var options = {};
var player = videojs('my-video', options, function onPlayerReady() {
this.on('ended', function() {
//do something here...
});
});
欧
var player = document.getElementById("my-video");
player.addEventListener("ended", function() {
//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')">
<source src="{{asset('promos/'.$course->id.'.mp4')}}" type="video/mp4">
<source src="{{asset('promos/'.$course->id.'.m4v')}}" type="video/ogg">
</video>
在 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>
我该如何解决这个问题?
我希望其中之一对您有所帮助
var options = {};
var player = videojs('my-video', options, function onPlayerReady() {
this.on('ended', function() {
//do something here...
});
});
欧
var player = document.getElementById("my-video");
player.addEventListener("ended", function() {
//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')">
<source src="{{asset('promos/'.$course->id.'.mp4')}}" type="video/mp4">
<source src="{{asset('promos/'.$course->id.'.m4v')}}" type="video/ogg">
</video>