-
Hello! I have tried, without success, to use a data-uri video as source for my background video. As I failed to have a working example, is it me, or is it simply impossible to have data-uri as source for background videos? For background images, it works. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Hello @hakimel, a small up in case you did not see this discussion :-) |
Beta Was this translation helpful? Give feedback.
-
Hi @jeertmans, when you provide a data-background-video with a comma in it, reveal uses it as "multiple sources" video, as mentioned in the doc here : https://revealjs.com/backgrounds/#video-backgrounds
In your situation, as a data-uri also contains a comma ( |
Beta Was this translation helpful? Give feedback.
-
As a workaround you can dynamically merge the two Reveal.on( 'slidechanged', event => {
// event.previousSlide, event.currentSlide, event.indexh, event.indexv
if (event.currentSlide.getAttribute('data-background-video')) {
const background = Reveal.getSlideBackground(event.indexh, event.indexv),
videoSources = background.querySelectorAll('video>source');
videoSources.forEach((source, i) => {
const src = source.getAttribute('src');
if(src.match(/^data:video.*;base64$/)){
const nextSrc = videoSources[i+1]?.getAttribute('src');
source.setAttribute('src', `${src},${nextSrc}`);
}
});
}
} ); |
Beta Was this translation helpful? Give feedback.
thank you for the jsfiddle, it is strange that it works well on my side and not in this fiddle, my supposition is that it's because I use markdown plugin and you use plain html slides, it may impact the order in which everything is parsed/displayed 🤷♂️
Anyway, I managed to fix the snippet by setting the
src
attribute on the<video>
element instead of the<source>
tag. This is also the recommended way to do so (https://stackoverflow.com/a/27934769).This way it works fine :
https://jsfiddle.net/kzpqxv94/1/
I also updated the code to make it work on first load (it was working on my side but again maybe because I use markdown).