【发布时间】:2020-11-07 01:29:55
【问题描述】:
<script>
var vid = document.getElementById("player");
$(function() {
var timeout;
$("#player").on("playing pause", function(e) {
// Save reference
var v = this
// Clear previous timeout, if any
clearTimeout(timeout)
// Call immediately if paused or when started
performaction(v.currentTime, v.duration)
// Set up interval to fire every 5 seconds
if (e.type === "playing") {
timeout = setInterval(function() {
performaction(v.currentTime, v.duration)
}, 5000)
}
})
function performaction(currentTime, duration) {
console.log(currentTime);
console.log(' ajax action goes here');
var data = { pause_time : currentTime };
$.ajax({
type: "POST",
url: '/instructor/promo_video/84',
data: data,
success: function() {
console.log("Value added");
}
})
}
})
</script>
在我的数据库中,我有一个视频表,其中的列名为
pause_time。 现在,如果我将此 js 代码用于视频当前播放时间,那么我将在控制台中获得 5 秒间隔后的时间。 我想在 laravel 中使用 ajax 将这个时间发送到数据库。以及如何在控制器中获取currentTime值。
提前致谢!!
【问题讨论】: