html5 onended,html - Angularjs HTML5 Video onended - Stack Overflow

Worked at this issue for a while and found a hack to the same problem that worked for me. Uses jQuery $timeOut function (you could also use the vanilla JS timeout, both are a typical hack with angular I find), and the html5 video events: "duration", "currentTime", and "timeupdate", which you can learn more about here. Using those event values you can calculate the end of the video and simulate the html5 video "ended" event. Here's the code

myCtrl.myVideo = document.getElementbyId("my-video-id"); //you need to have an id for your html5 video

//function to define in the controller

myCtrl.videoListener = function()

{

//javascript event listener function

myCtrl.myVideo.addEventListener('timeupdate',

function()

{

myCtrl.myVideo = this; //define "this"

var videoDuration = this.duration;

var videoCurrentTime = this.currentTime;

if (videoCurrentTime >= videoDuration)

{

//wrapping in a $timeOut function is the only way this works!

$timeout(function(){

//do something when the video ends, set variables, etc.

}, 0);

}

else if (videoCurrentTime < videoDuration)

{

//wrapping in a $timeOut function is the only way this works.

$timeout(function(){

//do something while the video is playing, set variables, etc.

}, 0);

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值