I am developing a javascript application where I have to do this.
Check every 5 seconds that whether the page contains an element with tag.
Once, the tag is detected, then start my video tracking function.
DO NOT check again every 5 seconds that whether the page contains an element with tag - once a tag has been detected and my video tracking function has been started.
Here is my code:
<script>
setInterval(function() {
var myVideo = document.getElementsByTagName('video')[0];
console.log(myVideo);
if (myVideo != null)
{
myVideo.id = 'video-stream';
var colors = new tracking.ColorTracker(['magenta', 'cyan', 'yellow']);
colors.on('track', function(event) {
if (event.data.length === 0) {
// No colors were detected in this frame.
} else {
event.data.forEach(function(rect) {
console.log(rect.x, rect.y, rect.height, rect.width, rect.color);
});
}
});
tracking.track("#video-stream", colors);
}
}, 5000);
</script>
Right now, it just keeps checking even if a tag is detected, So how do I stop it from checking once it if (myVideo != null)
condition is fulfilled and it has gotten into it?
Any suggestions will be highly appreciated.