I am using videojs to build a website to play videos and insert some images to the page at certain time point of the video being played. I used the code below to get the current time and insert an image in "imageContext" div.
<script type="text/javascript">
var myPlayer = document.getElementById("example_video_1");
var added = false;
var ShowAds=function(){
var time = myPlayer.currentTime;
var img = document.createElement('IMG');
div = document.getElementById("imageContext");
div.style.width = '100px';
div.style.height = '100px';
div.style.display = 'inline-block';
if(time > 30 && time <= 40 && !added){
//img.onload = function(){
div.appendChild(img);
added = true;
img.setAttribute("src",'/Applications/MAMP/htdocs/shqc.jpg');
img.style.width = '100%';
img.style.height = 'auto';
}else if(time > 70){
//change to another image in the same position
}
}
myPlayer.addEventListener('timeupdate',ShowAds,false);
</script>
What if I want to show another image on the page when the time changes to, say, the 90th second? Or is there any way to delete the image on the page using javascript? Thanks!
To be clear, I have tried to put
img.setAttribute("src",'/Applications/MAMP/htdocs/yy.jpeg');
under else, it doesn't work