Automatic Full-Screen Switching Upon Video Playback in HTML5

Currently, I have a video clip set to play when the timer reaches a certain point. My goal is for the video to automatically enter full-screen mode when it starts playing and return to its original position when it stops, as the timer will continue ticking.

I am aware of the requestFullScreen() method, but I am unsure of how to call it when the video begins playing. Any assistance with this matter would be greatly appreciated. Thank you!

Best regards!

Answer №1

let newVideo = document.createElement('video');

newVideo.src = 'videoURL.mp4';
newVideo.style.width = window.innerWidth;
newVideo.style.height = window.innerHeight;
newVideo.autoplay = true;

document.getElementById('video-container').appendChild(newVideo);

Answer №2

Do you need code similar to this?

player = document.getElementById('video');

function startPlaying(){
    player.play();
}

player.onPlay = function() {
    if (player.requestFullscreen) {
       player.requestFullscreen();
    } else if (player.msRequestFullscreen) {
       player.msRequestFullscreen();
    } else if (player.mozRequestFullScreen) {
       player.mozRequestFullScreen();
    } else if (player.webkitRequestFullscreen) {
       player.webkitRequestFullscreen();
}
};

player.onended = function(e) {
  if(player.exitFullscreen) {
    player.exitFullscreen();
  } else if(player.mozCancelFullScreen) {
    player.mozCancelFullScreen();
  } else if(player.webkitExitFullscreen) {
    player.webkitExitFullscreen();
  }
};

Answer №3

Try implementing this code snippet:

<script>
window.onload = function(){
    var element = document.getElementById("OnTick"); 
    element.addEventListener("click", function(){
        element.style.display = 'none';
        var videoContainer = document.getElementById('video1');
        var newVideo = document.createElement('video');

        videoContainer.style.width = window.innerWidth;
        videoContainer.style.height = window.innerHeight;

        newVideo.src = 'http://techslides.com/demos/sample-videos/small.mp4';
        newVideo.style.width = "100%";
        newVideo.autoplay = true;
        newVideo.controls = true;

        videoContainer.appendChild(newVideo);

    }, false); 
}
</script>
<body style='margin:0px'>
    <div id='video1' style='overflow: hidden;'></div>
    <span id='OnTick' style='width:20px;height:20px;background-color:#323232;display:block'>  </span>
</body>

Unfortunately, the autoplay feature may not work in some cases.

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

Select and activate a single input from multiple options in Angular

I have multiple input fields with corresponding buttons that enable the input when clicked. I would like the behavior of the buttons to work in such a way that when one button is clicked, only that specific input field is enabled while the others are disab ...

How can you create a basic slideshow without relying on jQuery to cycle through images?

Imagine you have a div containing 3 images. Is there a way to build a basic slideshow that smoothly transitions between the images, showing each one for 5 seconds before moving on to the next one and eventually looping back to the first image without rely ...

Tips for reorganizing the JSON data created by Artoo.js?

My file aims to scrape data from a single webpage, but I've hit a roadblock. I initially tried using artoo, request, and cheerio based on my research. Here's the code I have so far: request('http://www.ciclopi.eu/frmLeStazioni.aspx?ID=144&a ...

JSON function invocation is failing to load

This is my JavaScript script, When I call the function calculate(), the JSON method ConvertDataTabletoString() only gets called once, when I load the page. I want the method to be called every 5 seconds. I am calling a VB.NET function in .aspx. How can ...

Can I update a label using ajax from the controller?

Hello everyone, I am facing a challenge in changing the text label coming from my Controller's JsonResult. There are two specific issues that I am encountering: 1) I am having difficulty displaying the text sent from my controller onto my view... ...

IframeResizer.js is automatically readjusting its position to the top left corner (0,0) when a javascript event or

Within our internal web environment, I have implemented IframeResizer.js in a rather basic manner. The child page contains a table generated by a third-party application with mouseover/hidden and javascript tags associated with the TH elements (including a ...

The error message appeared as a result of the bluebird and mongoose combination: TypeError: .create(...).then(...).nodeify is

Recently, I encountered an issue while attempting to integrate bluebird with mongoose. Here's the scenario: I wrote some test code using bluebird without incorporating mongoose, and it worked perfectly. The code looked something like this: A().then( ...

Open the link and input the text into the text box?

Suppose I have the following JavaScript code: <script language="javascript" type="text/javascript"> function addText() { var newText = document.myForm.inputText.value; document.myForm.description.value += newText; } </script> I want t ...

Calculate a value within a MongoDB field

Hello everyone, I have a document in my collection that looks like this: { Player_Name: Sandeep Nair Player_TotalWeightedPoints: 80 Player_Rank: 23 } I have around 200 similar documents in my collection. The Player_Rank is determined by the total Weighted ...

What could be the reason for the ReferenceError that is being thrown in this code, indicating that '

let number = 1; console.log(number); Feel free to execute this basic code snippet. You may encounter an issue: ReferenceError: test is not defined, even though the variable was declared. What could be causing this unexpected behavior? ...

Comparing the size of a MongoDB array to another field in a document: how can it be done?

Need guidance on querying MongoDB for documents that have a specific number of users in them. This needs to be done through both the mongo console and JavaScript in Node.js: db.turnys.find( { users:{$size:seats } } ) The structure of turnydb.turnys colle ...

The final DOM is not loading properly when using Jest and React Testing Library during page initialization

I'm currently working on testing my React application with Jest and React Testing Library. During this process, I am attempting to verify that the login page displays a specific message once it has fully loaded. Upon initial loading of the login page, ...

Using jQuery AJAX to call a WebMethod and display the first row of data received

I am currently facing an issue with my JQUERY code where I am expecting to see 3 json results in the console, but instead I am seeing 3 duplicate copies of the first result. For example, when trying to display filenames, I am getting back "first name, fir ...

When attempting to call an API using the Angular HttpClient, an issue is encountered

I am having trouble displaying my JSON data in my application. I have imported the HttpClientModule in app.module.ts, but I keep getting an error that says: "" ERROR Error: Cannot find a differ supporting object '[object Object]' of ty ...

The announcement will not be made as a result of the utilization of a private name

I've been working on transitioning a project to TypeScript, and while most of the setup is done, I'm struggling with the final steps. My goal is to use this TypeScript project in a regular JavaScript project, so I understand that I need to genera ...

Targeting child elements with CSS selectors

In my ecommerce software, I have a menu that I want to customize by making the main categories bold. I have attempted various methods, including the ones shown below, but I am struggling to target the correct elements (specifically those in capital letter ...

Tips on using Bootstrap 4 containers within a container-fluid and ensuring text stays within a container at all times

What is the best way to incorporate a Bootstrap 4 container within a container-fluid? how can we ensure that text is always contained within the blue section? ...

How to Send an Array to AJAX and Retrieve the Data in Codeigniter Controller

I am attempting to retrieve table data, store it in an array, and pass it to the controller so I can write it in PHP Excel. Previously, I had success with other data but now my excel file is turning up empty. Below is the JavaScript code snippet: var Ta ...

What is the method to permanently install and enforce the latest version using npm?

We are implementing a private npm module for exclusive use within our organization. Given that the module is managed internally, we have confidence in version updates and changes. Is there a way to seamlessly install this module across multiple projects s ...

merge various CSS styles into a single one

My div has a mix of styles applied to it. <div class="alert alert-secondary login-alert" role="alert">Please contact the administrator to receive credentials!</div> The styles alert and alert-secondary are default styles from bootstrap 4, whi ...