mp4 not playing as expected on the qa link | Community
Skip to main content
Level 2
September 21, 2022
Solved

mp4 not playing as expected on the qa link

  • September 21, 2022
  • 1 reply
  • 1184 views

Hi All,

 

I am trying run a target test which involves an mp4.
The code runs absolutely fine when checked on console but when the same code is pushed via target, the video doesn't get rendered and the source of the video appears on the top of the div.

 

Doesn't target support mp4 ?

Can someone pls help me with a solution to this ?

Thank you so much in advance!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Perrin_Ennen

You can wait here with on document loaded - there is certainly also more elegant way.

function yourFunction () {
  console.log("document loaded");
}

(document.readyState != 'complete') ? document.addEventListener('DOMContentLoaded', function() { yourFunction() }) : yourFunction();

You'll probably do something like this:

function addSourceToVideo(element, src, type) {
    var source = document.createElement('source');
    source.src=src;
    source.type = type;
    element.appendChild(source);
}

var video = document.createElement('video');
document.body.appendChild(video);  
addSourceToVideo(video, '<YOUR_VIDEO_URL>.mp4', 'video/mp4');  
video.play(); // Hope you do it differently - because that doesn't work nowadays, because e.g. Google doesn't allow this anymore because of autoplay - and you get an error towards something like this "..failed because the user didn't interact with the document first."

Hope this helps you a bit.

 

..and no, I don't have a blog yet. But you can follow me here.

 

1 reply

Perrin_Ennen
Community Advisor
Community Advisor
September 26, 2022

To me it just sounds like something is wrong with the timing. Especially if it works from the console - but not from target. Wait for document loaded or similar - and then execute your code.

shravya20Author
Level 2
September 26, 2022

HI Perrin

Can we execute a code on document load from Target ?
Do you have any blog which I can follow ?

 

Thank you

Perrin_Ennen
Community Advisor
Perrin_EnnenCommunity AdvisorAccepted solution
Community Advisor
September 26, 2022

You can wait here with on document loaded - there is certainly also more elegant way.

function yourFunction () {
  console.log("document loaded");
}

(document.readyState != 'complete') ? document.addEventListener('DOMContentLoaded', function() { yourFunction() }) : yourFunction();

You'll probably do something like this:

function addSourceToVideo(element, src, type) {
    var source = document.createElement('source');
    source.src=src;
    source.type = type;
    element.appendChild(source);
}

var video = document.createElement('video');
document.body.appendChild(video);  
addSourceToVideo(video, '<YOUR_VIDEO_URL>.mp4', 'video/mp4');  
video.play(); // Hope you do it differently - because that doesn't work nowadays, because e.g. Google doesn't allow this anymore because of autoplay - and you get an error towards something like this "..failed because the user didn't interact with the document first."

Hope this helps you a bit.

 

..and no, I don't have a blog yet. But you can follow me here.