How Can I Play Only Those Videos Where Current Time Is Greater Than Start Time Using Java Script? August 14, 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 JugaHow To Put React Component Inside Html String?Validate And Filter Email Address With Regex?How Do Javascript Engine Count Number Of Tag Of The Html Document Is Ill-formed?$(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 postsHow Find Emojis By Name In Discord.jsReact Router Doesn't Work On Express ServerFading In Background Image With JquerySet Style With :hover Javascript 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?"