Skip to content

Instantly share code, notes, and snippets.

@fataelislami
Created February 24, 2021 04:41
Show Gist options
  • Save fataelislami/49a128d2b1dfb9f0879303bcf0888270 to your computer and use it in GitHub Desktop.
Save fataelislami/49a128d2b1dfb9f0879303bcf0888270 to your computer and use it in GitHub Desktop.
var video = document.getElementById('video');
var supposedCurrentTime = 0;
window.onload = function() {
video.addEventListener("error", function(event) {
video.src = "<?= 'https://file.luarsekolah.com/storage/course/'.str_replace(' ', '%20', $loadSubChapter->video); ?>";
});
video.src = "<?= getConfiguration()->video_server.'/storage/course/'.str_replace(' ', '%20', $loadSubChapter->video); ?>";
}
function changeVideo(videoData){
video.src = "<?= getConfiguration()->video_server.'/quality/'; ?>"+videoData;
video.addEventListener("error", function(event) {
video.src = "<?= 'https://file.luarsekolah.com/quality/'; ?>"+videoData;
});
video.currentTime = supposedCurrentTime;
}
function changeVideoOriginal(){
video.src = "<?= 'https://file.luarsekolah.com/storage/course/'.str_replace(' ', '%20', $loadSubChapter->video); ?>";
video.currentTime = supposedCurrentTime;
}
video.addEventListener('timeupdate', function() {
if (!video.seeking) {
// supposedCurrentTime = video.currentTime;//uncomment ini untuk disable fast and back
supposedCurrentTime = Math.max(supposedCurrentTime, video.currentTime);
var duration=video.duration;
var current_time=video.currentTime;
if(current_time==duration){
insertJourney(<?= $course_user_id ?>,<?= $subchapter_id?>);
}
}
});
// prevent user from seeking
video.addEventListener('seeking', function() {
// guard agains infinite recursion:
// user seeks, seeking is fired, currentTime is modified, seeking is fired, current time is modified, ....
var delta = video.currentTime - supposedCurrentTime;
// if (Math.abs(delta) > 0.01) {//uncomment ini jika ingin disable fast and back
if (video.currentTime > supposedCurrentTime) {
// console.log("Seeking is disabled"+Math.abs(delta));
// alert("Video tidak dapat dipercepat!");
var ml='<?= $this->session->userdata('id') ?>';
if(ml!='3027'){
swal({
title: '',
text:'Video tidak dapat dipercepat!',
timer: 1000,
icon: "error",
showCancelButton: false,
showConfirmButton: false,
buttons: false,
}).then(
function () {},
// handling the promise rejection
function (dismiss) {
if (dismiss === 'timer') {
//console.log('I was closed by the timer')
}
}
)
video.currentTime = supposedCurrentTime;
}
}
});
// delete the following event handler if rewind is not required
video.addEventListener('ended', function() {
// reset state in order to allow for rewind
supposedCurrentTime = 0;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment