i have this simple script that i found in the webRTC doc i triet to run it but it seems i'm missing something
const leftVideo = document.getElementById('leftVideo');
const rightVideo = document.getElementById('rightVideo');
leftVideo.addEventListener('canplay', () => {
const stream = leftVideo.captureStream();
rightVideo.srcObject = stream;
});
i get this error on stream capture when i inspect it Uncaught DOMException: Failed to execute 'captureStream' on 'HTMLMediaElement': Cannot capture from element with cross-origin data at HTMLVideoElement.leftVideo.addEventListener this my index.html
<video id="leftVideo" playsinline controls loop muted>
<source src="test1.webm" type="video/webm"/>
<p>This browser does not support the video element.</p>
</video>
<video id="rightVideo" playsinline autoplay></video>
<video crossOrigin="anonymous" src="https://cdn.myapp.com:81/video.mp4"></video>
you want to make sure link is using https
Reference: https://stackoverflow.com/a/35245146/8689969
// Fetch the original image
fetch(video.filePath, {
mode: 'cors',
headers: {
'Access-Control-Allow-Origin':'*'
}
})
// Retrieve its body as ReadableStream
.then(response => {
const reader = response.body.getReader();
return new ReadableStream({
start(controller) {
return pump();
function pump() {
return reader.read().then(({ done, value }) => {
// When no more data needs to be consumed, close the stream
if (done) {
controller.close();
return;
}
// Enqueue the next data chunk into our target stream
controller.enqueue(value);
return pump();
});
}
}
})
})
.then(stream => new Response(stream))
.then(response => response.blob())
.then(blob => URL.createObjectURL(blob))
.then((url) => {
// gives the blob url which solves cors error in reading stream(using captureStream() func)
console.log(url);
// do your thing
})
.catch(err => console.error(err));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With