I want some help in debugging my code. I want to revoke objectURL after loading the video but onload event is not firing. Any help will be very appreciated Here is some of my code:
////////////// uploading video $(".new-video input:file").on('change',function () { showSpinner(); $(".video-controls").show(); $("#video1").attr('loop', false); if (this.files && this.files[0]) { showSpinner(); var URL = window.URL || window.webkitURL; var file = this.files[0]; var type = file.type; var videoNode = document.querySelector('#video1'); var canPlay = videoNode.canPlayType(type); if (canPlay === '') canPlay = 'no'; var message = type + " File is not supported. Please select other file"; var isError = canPlay === 'no'; if (isError) { alert(message+","+ isError); return } var fileURL = URL.createObjectURL(file); videoNode.src = fileURL; // revoking video element src videoNode.onload = function(){ hideSpinner(); URL.revokeObjectURL(this.src); alert("inside") } } });
<div class="video-container"> <img class="bg-img content-container" src="/"> <video id="video1" class="small-video content-container" autoplay muted></video> </video> </div> <button class="new-video"> <input type="file" accept="video/*"> </button>
According to W3Schools (yes I know), during the loading process of an audio/video, the following events occur, in this order:
loadstart
durationchange
loadedmetadata
loadeddata
progress
canplay
canplaythrough
So you're looking for the loadeddata
event:
videoNode.onloadeddata = function(){
hideSpinner();
URL.revokeObjectURL(this.src);
alert("inside")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.