Step-by-step guide for configuring clock and video timestamps using javascript and html5

I am looking to create a dynamic webpage that features both a digital clock and a video element. The unique aspect of this page is that when the clock reaches the 35th second of each minute, the video should automatically start playing.

For example, if the time is exactly 21:00:35, a 15-second video clip will begin playing. Once the video finishes, it will pause until the clock reads 21:01:10. At this point, the same 15-second video clip will play again, repeating the cycle every 35 seconds.

function displayCurrentTime() {
  var currentdate = new Date();
  var hours = currentdate.getHours(); // 0 - 23 
  var minutes = currentdate.getMinutes(); // 0 - 59
  var seconds = currentdate.getSeconds(); // 0 - 59

  if (hours < 10) {
    hours = "0" + hours;
  }
  
  if (minutes < 10) {
    minutes = "0" + minutes;
  }
  
  if (seconds < 10) {
    seconds = "0" + seconds;
  }

  var currentTime = hours + ":" + minutes + ":" + seconds;
  document.getElementById('myClock').innerText = currentTime;
  document.getElementById('myClock').textContent = currentTime;

  setTimeout(displayCurrentTime, 1);
}

displayCurrentTime();
<i>
  <video width="320" height="240" controls>
    <source src="Myvid01.mp4" type="video/mp4">    
  </video>
</i>

Answer №1

I'm a little confused by the example you provided, so please forgive me. If all you want is for the video to start when the clock reaches the 35th second of every minute, you can simply assign an id to your video element:

When the clock hits the 35th second of each minute, then the video should begin playing.

Then, within your function, you can check if the current second is equal to 35 and call the play() method on the player:

<video id="player" width="320" height="240" controls>
if (s === 35 ) {
    player.play();
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Upgrade your Vue 2 app with the magical powers of Vue 3 Teleport

By utilizing the teleport feature in Vue 3, you can move a component to the body tag with ease: <template> <button @click="modalOpen = true"> Open full screen modal! (With teleport!) </button> <teleport to=&quo ...

Having trouble populating input field with data returned from ajax request

Performing an Ajax Request $.ajax({ type: "GET", url: "http://localhost/CI2/index.php/login/testfunc", data: {macro: selectedmacro}, async: false, success: function (data) { $('#tinyeditor').val(data); $(&apos ...

pass extra parameters to breeze-saving-server functions

Currently, I am working on a project using Durandal. In order to retrieve and save data, I am using Breeze. However, I am facing an issue where I need to send additional parameters to the server when saving, such as the user who is saving the entity. The s ...

I am utilizing the useEffect react hook to retrieve data from a server

I'm currently working on fetching data from a server using the fetch API and displaying it in an unordered list with unique keys generated by uuidv4. I'm using React's useEffect hook to handle this process, but I'm encountering an issue ...

I'm trying to create a transparent v-card, but for some reason it's not turning out the way I want

How can I make the v-card transparent while keeping its content opaque using CSS? card.vue <v-card class="cardColor"> <v-card-text> TEXT </v-card-text> <v-card-actions> <v-btn color="prima ...

What could be causing the CSS transition to fail when the menu button is clicked?

After clicking on the menu, a class 'active' is added to both the 'div' and 'section' elements. https://i.stack.imgur.com/jbamR.png The following javascript code accomplishes the above functionality: <script> const ...

Achieve stacking one div on top of another without specifying a position and utilizing inline CSS only

Currently, I am working on creating a unique design for a letter that will be sent out to customers via my website. In my efforts to achieve this, I came across a simple design that caught my eye. To view the design inspiration, visit this link My goal i ...

When Electron's WebView.loadURL is called, it initiates a reloaded page

According to the documentation provided by Electron, it is necessary to wait until the webview element is available in order to utilize its respective methods. While most methods function properly, I am facing challenges in understanding how to programmati ...

No reply received on the web browser

I have written a code that is intended to read a JSON file and display it in the browser. The code is functioning correctly as it prints the data to the console, but for some reason, the data is not displaying on the browser. app.post("/uploadfile&q ...

Injecting resolve into Angular controller and encountering undefined value in logging operation

My setup involves the following: .state('posts', { url: '/posts/{id}', templateUrl: 'posts.html', controller: 'postsController as postsCtrl', resolve: { post: getSinglePostWrapper ...

Using v-model with checkboxes in vue.js: A Step-by-Step Guide

How can I use a checkbox with a v-model in Vue2.js? <input type="checkbox" value="test" :checked="selected"/> I need the value of the checkbox to be test, and I also require two-way binding with the prop named selected, ...

Setting the modal option to false in a Messi pop-up dialog box

After attempting to close the Messi pop-up with "$('.messi').remove();" I encountered an issue where the modal set in the pop-up persisted even after its removal, hindering any changes to the web page. Is there a manual way to set modal:false? ...

Is there a way to halt AngularJs code for Bootstrap Confirmation Dialog?

Currently, I am in the process of updating old Style window.confirm dialogue boxes to use a Bootstrap Dialogue box. In order to achieve this, I have integrated a JavaScript function within an Angular code snippet as shown below: function showConfirmation( ...

The axios GET request failed to return a defined value

My current issue involves making a get request using the following code snippet: router.get('/marketUpdates',((request, response) => { console.log("market updates"); var data: Order[] axios.get('http://localhost:8082/marketUpdates& ...

Using Typescript with d3 Library in Power BI

Creating d3.axis() or any other d3 object in typescript for a Power BI custom visual and ensuring it displays on the screen - how can this be achieved? ...

What is the best method for retrieving content through ajax.get or ajax.load when the external content is dynamically generated by ajax?

How can I retrieve content from an external HTML file that is mostly generated client-side? When I try to access the file, I don't get the expected content. Here is the code snippet I am currently using: $.ajax({ url: '*************** ...

Toggle the visibility of table TDs by clicking on a specific TD cell

I came across a solution that perfectly addressed my issue, but I'm struggling to implement it in my code correctly. I managed to get it to work initially, but then everything suddenly stopped functioning... Show or hide table row if user clicks on i ...

Is there a way to implement a JQuery Keyup event listener on all forms within a webpage

Can keyup with jQuery be utilized for multiple form input fields without knowing their specific ID, but only their class or containing div? Here is an example of it working with a specific form ID "add": $(add).keyup(function () { value = $(add).val() ...

Encountering TypeError with Angular2's AsyncPipe and Observable when trying to retrieve a property (TypeError: Unable to access property ... from null)

I am attempting to access a property of an object returned by an Observable. Despite finding examples on Stack Overflow, I am encountering errors in my own application. You can replicate the same error in Plunker: http://plnkr.co/edit/X5xNDOFmCpLOnzv4X0x ...

Ways to resolve encoded titles in Youtube API search results

I am currently utilizing the youtube-search 1.1.4 package to search for videos. However, I am encountering an issue where the titles of the results are encoded with &amp; or &#39; instead of simply & and ' and so forth. For instance, an e ...