Solution 1 :
i hope that one of this is helpful
var options = {};
var player = videojs('my-video', options, function onPlayerReady() {
this.on('ended', function() {
//do something here...
});
});
Ou
var player = document.getElementById("my-video");
player.addEventListener("ended", function() {
//do something here...
});
Solution 2 :
As Jsplayer not worked correctly I used html5 video player and it is fine:-
<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>
Problem :
In Laravel project ,I have video vjs player as in this code :
<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>
I want after the video end of play do and action (add data to server),I did this but don’t work :
<script>
var vid = document.getElementById("my-video");
vid.onended = function() {
alert("The video has ended");
};
</script>
How can I solve this?
Comments
Comment posted by SM_Berwari
the script is at the below of page
Comment posted by SM_Berwari
I used addEventListener : vid.addEventListener(‘ended’, (event) => { action}; ,but stil don’t work
Comment posted by videojs.com
I am using this :
Comment posted by wissem chiha
plugin javascript for html video, you can install it via npm
Comment posted by SM_Berwari
is i must install it or using cdn link enough
Comment posted by SM_Berwari
the first code make the video don’t start to play ,and second one don’t work
Comment posted by wissem chiha
yes u can use CDN link, and don’t hesitate to read few docs on how to integrate it in your project, it’s so simple
Comment posted by wissem chiha
i know that’s for event end, that’s what are u want ?