Javascript, dynamically change Video-Url - Video URL is set / Just Placeholder Poster Shown

Viewed 323

i want to dynamically change the Urls of two Videos. My Problem is that the first Video's URL is getting Changed and plays correctly and the second Video just changes the Videos-Url without Playing it. The Second Video still shows the Placeholder-Poster.

Without changing the Video.source.src my Page looks like This: enter image description here

<div class="container-fluid" id="container">
    <div class="cocoen">
        <video loop autoplay muted poster="img/placeholder_0.png">
            <source type="video/mp4">
        </video>
        <video loop autoplay muted poster="img/placeholder_1.png">
            <source type="video/mp4">
        </video>
    </div>
  

When trying to set the Video-Sources (yes, i know that both video-urls are the same, its just for test purposes :p)

var urls = ["img/small_1.mp4", "img/small_1.mp4"];
var sources = $("video > source").toArray();
sources[0].src = urls[0];
sources[1].src = urls[1];

startVideos();

Only the first (left) one is working: enter image description here But the Sources are correctly set on both videos. enter image description here

I want to change the URLS more then Once, so just setting the URLS in the HTML isnt an Option. If i set the src of video#1 to movie1 in html and video#2.src to movie2 and use JS to set video#1.src = movie2 and video#2.src=movie1 only the left video changes in display even tho the html has the correct src's.

enter image description here

I dont know if this Information is important, but this is how i start the Videos, after i set the URLS:

function reduceRetryOnError(array, callbackFunction, functionToRetry) {
    success = array.reduce((acc, value) => acc && callbackFunction(value));
    if (!success) {
        console.log("Reduce failed: Retry in 300 ms");
        setTimeout(functionToRetry(), 300);
    }
}

function startVideos() {
    function startVideo(video) {
        if (!video) {
            return false;
        }

        if (video.paused) {
            video.play();
        }

        return true;
    }
    reduceRetryOnError($("video").toArray(), startVideo, startVideos);
}

I also tried to Pause and the start the Video again within the Starting Function.

Ty in advanced.

0 Answers
Related