Is it a good idea for the poster image to vanish too quickly before the video starts playing in HTML5?

Recently, I implemented a full-width background video on my website at www.sparkengine.tv. While the site is still a work in progress, some users have reported seeing the poster image before it disappears right before the video loads, creating a less-than-seamless transition. I would like to achieve a smoother effect where the still poster image gradually transitions into motion.

Upon exploring other websites, I noticed that they do not experience this issue...

Is this a common occurrence? Is there a solution available?

Sincerely, Henry

Answer №1

If I wanted to accomplish this, I might take the following approach:

  1. Disable autoplay for the videos.
  2. Insert the following script:

    Var vid = document.getElementById("bgVid"); vid.oncanplay = vid.play();

Another option to consider could be:

vid.oncanplaythrough = vid.play();

Answer №2

After exploring various options, I came up with a solution that looks something like this:

Here is the HTML code:

<div id="video-container" style="position:relative; overflow:auto">
 <img src="poster.jpg" id="videoposter" width=600 style="position:absolute; z-index:2" />
 <video src="video.mp4" poster="poster.jpg" style="width:600px; height:400px"></video>
</div>

<a href="#" id="videoplay">Play the video</a>

And here is the JavaScript part:

var video = document.getElementById('videoelement');

var btn_play = document.getElementById('videoplay');
btn_play.onclick = function() {
 video.currentTime = 0;
 video.play();
};

video.onloadeddata = function() {
 document.getElementById('videoposter').style.display = 'none';
};

Answer №3

In my opinion, it's quite common for the poster image to fade out before a video starts playing. One way to address this issue is by placing an image in front of the video. Once you instruct the video to begin playing, wait for the 'playing' event to be triggered on the video element. Subsequently, hide or quickly fade out the image.

You could implement a solution like this:

var playedBefore=false,myvideo=document.getElementById('myvideo')
myvideo.addEventListener('playing',
    function(){
        if(!playedBefore){
            setTimeout(function(){
                document.getElementById('myposter').style.display='none';
            },100);// Just a little extra time.
        }
        playedBefore=true;
    });
myvideo.play();

You can experiment with different events and function calls at http://www.w3.org/2010/05/video/mediaevents.html.

Another suggestion is to invoke the load() method on the video some time before initiating playback, ensuring that the video is prepared to play when play() is called.

For a demonstration incorporating all these elements, along with a fade effect on the poster, check out this JSFiddle: http://jsfiddle.net/jdwire/CM4dg/

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

Having trouble implementing the center edge effect in this CSS design

Looking for help with CSS to center the edges of a family tree design. Has anyone experience in working on styling family trees? *, *:before, *:after { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .tree { ...

Encountered a 400 error when attempting to send a request to a RestController in Spring MVC

I keep getting a "bad request 400" error when sending a request with parameters to the controller. I have double-checked the syntax but can't find any mistakes. Can someone please review my code and see what's wrong? var url = contextPath+"/bill ...

What is the best way to ensure that an ASync function only continues once all necessary information has been collected?

retrieveStudentGrades() { let grades = {}; let totalStudents = this.state.studentDetails.length; let studentCount = 0; this.state.courses.map((course) => { this.state.studentDetails.map((student) => { request.get( ...

Create a layered structure using a specified path

I am aiming to create a function that can accept an object path, like { 'person.data.info.more.favorite': 'smth' } and then output a nested object: { person: { data: { info: { more: { favorite: 'smth& ...

What is the best way to arrange form inputs in a single row?

My form consists of three input boxes. While the first two inputs are single line, the third is a description field with 10 rows set as default. However, for some reason, this third box is not aligned properly with the other two. Please refer to the screen ...

The divs descend one after another with no problems related to margins or padding

Having some trouble creating a unique WordPress theme with Bootstrap3. I can't seem to get my divs to behave properly and I've tried everything from display: inline, vertical-align: top, floats, clears, etc... but nothing seems to work. Here is ...

Apply a specific style conditionally using Angular's ng-repeat directive

Currently, I am utilizing ng-repeat to iterate through a list of divs and manually adding items to the JSON that is rendering these divs. My goal is to position the last div that I add in the JSON at the location where the mouse cursor is, while keeping th ...

Guide on showcasing AJAX Wikipedia API request in a HTML popup box

Two PHP scripts utilize the country name to retrieve relevant Wikipedia articles through an API. <?php // Display errors is set to on and should be removed for production ini_set('display_errors', 'On'); error_reporting(E_AL ...

Display the dropdown selection

I am trying to customize my dropdown menu so that when I hover over the main menu item (Sample Page), only the About submenu is displayed, not all of the dropdown menus. li.menu-item.dropdown .dropdown-menu { position: absolute; top: 70px; visibil ...

Utilizing Vue component data within inline CSS of a Vuetify component: a step-by-step guide

I am currently working on a list component that is dynamically generated from data and I have a specific requirement to style each item based on the color provided in the data. Here is an example of the Vue component: new Vue({ el: '#app', ...

With a simple click of a button, I aim to have the ability to set a variable to true

I am looking to create a button that changes to true in the Script section. This will allow for a random number to be displayed in the paragraph element. <!doctype html> <html> <button id="button"> random number </button> ...

What prevents Bootstrap 4 from breaking on mobile devices?

Here is the code I am working with: <div class="container-fluid"> <div class="row"> <div class="col-md-6"></div> <div class="col-md-6"></div> </div> </div> When I view this code in t ...

Trouble getting CSS to load in Webpack

I'm having some trouble setting up Webpack for the first time and I think I might be overlooking something. My goal is to use Webpack's ExtractTextPlugin to generate a CSS file in the "dist" folder, but it seems that Webpack isn't recognizi ...

Is there a way to reach (req , res) within a middleware function?

My custom Authorize Middleware allows only authorized users to access the dashboard: router.get('/dashboard', authorize(), dashboard); This function checks for user roles before granting access. Here is how it works: const jwt = require('e ...

Ensuring secure communication with PHP web service functions using Ajax jQuery, implementing authentication measures

jQuery.ajax({ type: "POST", url: 'your_custom_address.php', dataType: 'json', data: {functionname: 'subtract', arguments: [3, 2]}, success: function (obj, textstatus) { if( !('error' in obj) ) { ...

Instructions for outputting a string to the console in Javascript

I am looking for a versatile method to write a string to standard output in a portable manner, without automatically adding newlines at the end. I prefer it to utilize UTF-8 encoding and be compatible with: jrunscript (from any JDK) Rhino node.js Curren ...

How to efficiently manage multiple INSERT, SELECT, and UPDATE operations in mysql2 using nodejs

I am seeking guidance on how to approach a specific problem that I am facing. Due to my limited knowledge of databases, I am unsure of the best method to tackle this issue. The challenge I am dealing with involves receiving a 'large' amount of d ...

Utilizing Leaflet.js to dynamically incorporate layers through AJAX requests

I am currently facing an issue with my ASP.NET website that hosts a Leaflet map displaying data. I have implemented drop-down menus that trigger events through jQuery when changed. These events pass the selected values to a Web Service, which then retrieve ...

How can I determine the specific font used in an image through Google Fonts?

I remember seeing how to do this once on a website, possibly html5rocks, but now I can't seem to figure it out. Maybe there is someone out there who can help me with this. I want to know what font was used in this picture and if it is hosted on Googl ...

transferring information from Node.js/MongoDB to the front-end (invisible in the browser)

I am trying to retrieve data from a mongodb database and pass it to the front-end. The function I have written works in the console, where I can see an array containing elements. However, when I try to view it in the browser, it shows undefined. I am worki ...