Skip to main content
Level 2
September 21, 2022
해결됨

mp4 not playing as expected on the qa link

  • September 21, 2022
  • 4 답변들
  • 1224 조회

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!

이 주제는 답변이 닫혔습니다.
최고의 답변: 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.

 

4 답변

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.

shravya20작성자
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
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.