Skip to content

Commit

Permalink
autoplay muted background videos in speaker view #1037
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Oct 21, 2024
1 parent 8d7b03c commit 95946b4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

53 changes: 32 additions & 21 deletions js/controllers/slidecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ export default class SlideContent {
}
}
// Videos
else if ( backgroundVideo && !this.Reveal.isSpeakerNotes() ) {
else if ( backgroundVideo ) {
let video = document.createElement( 'video' );

if( backgroundVideoLoop ) {
video.setAttribute( 'loop', '' );
}

if( backgroundVideoMuted ) {
if( backgroundVideoMuted || this.Reveal.isSpeakerNotes() ) {
video.muted = true;
}

Expand Down Expand Up @@ -280,7 +280,9 @@ export default class SlideContent {
*/
startEmbeddedContent( element ) {

if( element && !this.Reveal.isSpeakerNotes() ) {
if( element ) {

const isSpeakerNotesWindow = this.Reveal.isSpeakerNotes();

// Restart GIFs
queryAll( element, 'img[src$=".gif"]' ).forEach( el => {
Expand All @@ -306,6 +308,9 @@ export default class SlideContent {

if( autoplay && typeof el.play === 'function' ) {

// In teh speaker view we only auto-play muted media
if( isSpeakerNotesWindow && !el.muted ) return;

// If the media is ready, start playback
if( el.readyState > 1 ) {
this.startEmbeddedMedia( { target: el } );
Expand Down Expand Up @@ -337,27 +342,33 @@ export default class SlideContent {
}
} );

// Normal iframes
queryAll( element, 'iframe[src]' ).forEach( el => {
if( closest( el, '.fragment' ) && !closest( el, '.fragment.visible' ) ) {
return;
}
// Don't play iframe content in the speaker view since we can't
// guarantee that it's muted
if( !isSpeakerNotesWindow ) {

this.startEmbeddedIframe( { target: el } );
} );
// Normal iframes
queryAll( element, 'iframe[src]' ).forEach( el => {
if( closest( el, '.fragment' ) && !closest( el, '.fragment.visible' ) ) {
return;
}

// Lazy loading iframes
queryAll( element, 'iframe[data-src]' ).forEach( el => {
if( closest( el, '.fragment' ) && !closest( el, '.fragment.visible' ) ) {
return;
}
this.startEmbeddedIframe( { target: el } );
} );

if( el.getAttribute( 'src' ) !== el.getAttribute( 'data-src' ) ) {
el.removeEventListener( 'load', this.startEmbeddedIframe ); // remove first to avoid dupes
el.addEventListener( 'load', this.startEmbeddedIframe );
el.setAttribute( 'src', el.getAttribute( 'data-src' ) );
}
} );
// Lazy loading iframes
queryAll( element, 'iframe[data-src]' ).forEach( el => {
if( closest( el, '.fragment' ) && !closest( el, '.fragment.visible' ) ) {
return;
}

if( el.getAttribute( 'src' ) !== el.getAttribute( 'data-src' ) ) {
el.removeEventListener( 'load', this.startEmbeddedIframe ); // remove first to avoid dupes
el.addEventListener( 'load', this.startEmbeddedIframe );
el.setAttribute( 'src', el.getAttribute( 'data-src' ) );
}
} );

}

}

Expand Down

0 comments on commit 95946b4

Please sign in to comment.