Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

mp4 not playing as expected on the qa link

Avatar

Level 1

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!

4 Replies

Avatar

Level 4

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.

Avatar

Level 1

HI Perrin

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

 

Thank you

Avatar

Level 4

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.

 

Avatar

Level 1

Hi Perrin,


Thank you so much for the codes.

I did try them out!
Its the same - working on console but failing when pushed via target. 😞

shravya20_1-1664453589174.png

This is what it looks on the target qa link.
Video doesnt get rendered and the URL appears on top.