How Can I Play Only Those Videos Where Current Time Is Greater Than Start Time Using Java Script? December 05, 2023 Post a Comment Unable to retrieve and play the videos Solution 1: You need to iterate through all the source elements and compare startat attribute.Also note, you should not have multiple id attributes having same valueTry this: Baca JugaDatetime From Utc In Local Time FormatWhy Does Queryselector Only Select The First Element And How Can I Fix This?How To Get The Next Obj When Looping In The Django Model$(document).ready(function() { var mediaPlayer = document.getElementById('media-video'); var videoSource = mediaPlayer.getElementsByTagName('source'); var d = newDate(); var hh = d.getHours(); var mm = d.getMinutes(); var ss = d.getSeconds(); var currentTime = hh + ':' + mm + ':' + ss; var a = currentTime.split(':'); var getStartTime = document.getElementById('videosource').getAttribute('startat'); Array.prototype.forEach.call(videoSource, function(elem) { var getStartTime = elem.getAttribute('startat'); if (currentTime >= getStartTime) { alert(elem.getAttribute('name')); var a = currentTime.split(':'); var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]); mediaPlayer.currentTime = seconds; mediaPlayer.play(); } }); });Copy<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><videoid="media-video"width="600"height="300"src="http://localhost/CastingGallery/upload/2/php.mp4"><sourceclass=""src="http://localhost/CastingGallery/upload/2/marimatrubhasha.mp4"id="videosource"type="video/mp4"startat="00:00:00"endat="00:04:07"name="Gujarati Bhasha"description="This is Gujarati Video"><sourceclass="active"src="http://localhost/CastingGallery/upload/2/php.mp4"id="videosource"type="video/mp4"startat="00:04:07"endat="00:19:06"name="PHP Video"description="This is PHP Video"></video>CopyFiddle here Share You may like these postsCollision Detection With Javascript On The Html Canvas Element Without Using JqueryYouTube API Not Muting In Safari (not IOS)How To Check Equality Of Two Objects(only Specific Key Values)Checking If Element Exists In Array Without Iterating Through It Post a Comment for "How Can I Play Only Those Videos Where Current Time Is Greater Than Start Time Using Java Script?"
Post a Comment for "How Can I Play Only Those Videos Where Current Time Is Greater Than Start Time Using Java Script?"